Skip to content

Commit

Permalink
fix(prerender): use decoded asset id to access prerendered asset head…
Browse files Browse the repository at this point in the history
…er overrides (#1588)
  • Loading branch information
danielroe authored Aug 16, 2023
1 parent 39851b8 commit 00361fb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 21 deletions.
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");
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

0 comments on commit 00361fb

Please sign in to comment.