astro
astro copied to clipboard
🐛 BUG: Dynamic image endpoint responds with `text/plain` MIME type in dev
What version of astro
are you using?
v1.0.0-beta.72
Are you using an SSR adapter? If so, which one?
none
What package manager are you using?
npm
What operating system are you using?
macOS / Stackblitz
Describe the Bug
A dynamic endpoint (a.k.a. non-HTML page) like src/pages/[slug].svg.ts
does not provide the correct MIME type with the response in dev mode. In my case, this is preventing generated SVG images from being shown.
As far as I can tell, this is because MIME types are only computed when a route has a pathname
:
https://github.com/withastro/astro/blob/963100fb27a88d444684ddb9a5d9dea31d4cd0ea/packages/astro/src/vite-plugin-astro-server/index.ts#L320
But when generating the manifest, pathname
is not set for dynamic routes.
https://github.com/withastro/astro/blob/963100fb27a88d444684ddb9a5d9dea31d4cd0ea/packages/astro/src/core/routing/manifest/create.ts#L260-L262
Would I be safe to calculate a fake “pathname” in vite-plugin-astro-server
to pass to mime.getType
?
Something like the following seems to work for me locally:
const pathname = route.segments.map(segment => segment.map(p => p.content).join('')).join('/');
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-6ame3m?file=src/pages/[slug].svg.ts
Participation
- [X] I am willing to submit a pull request for this issue.
Thanks for the issue, @delucis! I think adding the workaround you mentioned to vite-plugin-astro-server
makes sense as a quick fix. PRs welcome!
@natemoo-re This may be related to #3982