-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Closed
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When a prerendered route's static file is served via vite preview
, the content type is text/html
and not what is expected, in at least a few scenarios:
sitemap.xml
should beapplication/xml
manifest.webmanifest
should beapplication/manifest+json
atom.xml
and arguablyfeed.xml
should beapplication/atom+xml
rss.xml
should beapplication/rss+xml
Possibly others, but those are the only I'm aware of.
Given this is for the preview server, imo it'd be fine to simplify to:
*.xml
->application/xml
*.webmanifest
->application/manifest+json
Reproduction
npm i super-sitemap
- Create this route:
// /src/routes/sitemap.xml/+server.ts
import * as sitemap from 'super-sitemap';
import type { RequestHandler } from '@sveltejs/kit';
export const prerender = true;
export const GET: RequestHandler = async () => {
return await sitemap.response({
origin: 'https://example.com'
});
};
npm run build && npm run preview
Visit http://localhost:4173/sitemap.xml, open web inspector and observe content type is text/html
, not application/xml
as expected.
Or
// /src/routes/sitemap.xml/+server.js
export const prerender = true;
export async function GET() {
return new Response(
`
<?xml version="1.0" encoding="UTF-8" ?>
<urlset
xmlns="https://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="https://www.w3.org/1999/xhtml"
xmlns:mobile="https://www.google.com/schemas/sitemap-mobile/1.0"
xmlns:news="https://www.google.com/schemas/sitemap-news/0.9"
xmlns:image="https://www.google.com/schemas/sitemap-image/1.1"
xmlns:video="https://www.google.com/schemas/sitemap-video/1.1"
>
<url>
<loc>https://example.com/</loc>
</url>
</urlset>`.trim(),
{
headers: {
'Content-Type': 'application/xml'
}
}
);
}
Logs
No response
System Info
npmPackages:
@sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
@sveltejs/kit: ^1.25.1 => 1.25.1
svelte: ^4.2.1 => 4.2.1
vite: ^4.4.9 => 4.4.10
Severity
annoyance
Additional Information
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working