Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use decoded asset id to access prerendered asset header overrides #1588

Merged
merged 9 commits into from
Aug 16, 2023
2 changes: 1 addition & 1 deletion src/rollup/plugins/public-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions test/fixture/api/param/[id].ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default eventHandler((event) => {
setHeader(event, "Content-Type", "text/plain; charset=utf-16");
danielroe marked this conversation as resolved.
Show resolved Hide resolved
return event.context.params!.id;
});
10 changes: 5 additions & 5 deletions test/presets/cloudflare-pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
"/*",
Expand Down
15 changes: 0 additions & 15 deletions test/presets/vercel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
8 changes: 8 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down