withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.96k stars 2.5k forks source link

Injected routes are unable to reference a virtual entrypoint #6326

Closed natemoo-re closed 10 months ago

natemoo-re commented 1 year ago

What version of astro are you using?

2.0.14

Are you using an SSR adapter? If so, which one?

Any

What package manager are you using?

pnpm

What operating system are you using?

macOS

Describe the Bug

Expected astro:config:setup's injectRoute hook to support virtual file entry that is resolved by Rollup.

injectRoute({
  pattern: `_custom/[...slug]`,
  entryPoint: `virtual:custom`
})

Instead, I get a cryptic error:

error The URL must be of scheme file

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-lbykhk?file=astro.config.mjs,integration.js

Participation

natemoo-re commented 1 year ago

Confirming that this still happens on the latest. It seems like we're attempting to parse the specifier as a URL somewhere, which obviously doesn't work in this case.

lilnasy commented 11 months ago

That would be here:

https://github.com/withastro/astro/blob/8aa17a64b46b8eaabfd1375fd6550ff93727aa81/packages/astro/src/core/routing/manifest/create.ts#L193

ematipico commented 11 months ago

I wish we had a stricter way to pass the entry points. We could monkey patch it with a try/catch, but I believe this isn't the correct fix. We should change the API and make it more strict, to provide better validation.

ematipico commented 10 months ago

I am going to close this because we don't violate any documentation and it seems it isn't designed for that. If so, we should understand how this works at rollup level.