diff --git a/src/rollup/plugins/public-assets.ts b/src/rollup/plugins/public-assets.ts index efe8aef9f3..ab2a2d60a0 100644 --- a/src/rollup/plugins/public-assets.ts +++ b/src/rollup/plugins/public-assets.ts @@ -40,7 +40,7 @@ export function publicAssets(nitro: Nitro): Plugin { } assets[assetId] = { - type: nitro._prerenderMeta?.[id]?.contentType || mimeType, + type: nitro._prerenderMeta?.[assetId]?.contentType || mimeType, encoding, etag, mtime: stat.mtime.toJSON(), diff --git a/test/fixture/api/param/[id].ts b/test/fixture/api/param/[id].ts index a65b3fc6b9..86a4d93497 100644 --- a/test/fixture/api/param/[id].ts +++ b/test/fixture/api/param/[id].ts @@ -1,3 +1,4 @@ export default eventHandler((event) => { + setHeader(event, "Content-Type", "text/plain; charset=utf-16"); return event.context.params!.id; }); diff --git a/test/presets/cloudflare-pages.test.ts b/test/presets/cloudflare-pages.test.ts index 0eef08733a..c833c75a4c 100644 --- a/test/presets/cloudflare-pages.test.ts +++ b/test/presets/cloudflare-pages.test.ts @@ -51,11 +51,11 @@ describe("nitro:preset:cloudflare-pages", async () => { "/prerender/index.html.br", "/prerender/index.html.gz", "/api/hey/index.html", - "/api/param/foo.json/index.html", - "/api/param/hidden/index.html", - "/api/param/prerender1/index.html", - "/api/param/prerender3/index.html", - "/api/param/prerender4/index.html", + "/api/param/foo.json", + "/api/param/hidden", + "/api/param/prerender1", + "/api/param/prerender3", + "/api/param/prerender4", ], "include": [ "/*", diff --git a/test/presets/vercel.test.ts b/test/presets/vercel.test.ts index f4f72a310f..8a78cb8f99 100644 --- a/test/presets/vercel.test.ts +++ b/test/presets/vercel.test.ts @@ -28,21 +28,6 @@ describe("nitro:preset:vercel", async () => { "api/hey/index.html": { "path": "api/hey", }, - "api/param/foo.json/index.html": { - "path": "api/param/foo.json", - }, - "api/param/hidden/index.html": { - "path": "api/param/hidden", - }, - "api/param/prerender1/index.html": { - "path": "api/param/prerender1", - }, - "api/param/prerender3/index.html": { - "path": "api/param/prerender3", - }, - "api/param/prerender4/index.html": { - "path": "api/param/prerender4", - }, "prerender/index.html": { "path": "prerender", }, diff --git a/test/tests.ts b/test/tests.ts index 6f15a23dba..162ecf7bf7 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -320,6 +320,14 @@ export function testNitro( `); }); + it("stores content-type for prerendered routes", async () => { + const { data, headers } = await callHandler({ + url: "/api/param/prerender4", + }); + expect(data).toBe("prerender4"); + expect(headers["content-type"]).toBe("text/plain; charset=utf-16"); + }); + it.skipIf(ctx.preset === "deno-server")( "resolve module version conflicts", async () => {