Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 07217c0

Browse files
authored
fix(netlify): 404 has wrong content-type header (#162)
1 parent 0c1d117 commit 07217c0

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

.changeset/large-fireants-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/netlify': patch
3+
---
4+
5+
Fixes bug where prerendered 404 pages were served as `text/plain` instead of `text/html` for hybrid/server apps, leading to browsers displaying source code instead of rendering it

packages/netlify/src/ssr-function.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@ export const createExports = (manifest: SSRManifest, { middlewareSecret }: Args)
2222
return async function handler(request: Request, context: Context) {
2323
const routeData = app.match(request);
2424
if (!routeData && typeof integrationConfig.notFoundContent !== 'undefined') {
25-
return new Response(integrationConfig.notFoundContent, { status: 404 });
25+
return new Response(integrationConfig.notFoundContent, {
26+
status: 404,
27+
headers: { 'Content-Type': 'text/html; charset=utf-8' },
28+
});
2629
}
2730

2831
Reflect.set(request, clientAddressSymbol, context.ip);

packages/netlify/test/functions/redirects.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('SSR - Redirects', () => {
3535
const { default: handler } = await import(entryURL);
3636
const resp = await handler(new Request('http://example.com/nonexistant-page'), {});
3737
expect(resp.status).to.equal(404);
38+
expect(resp.headers.get("content-type")).to.equal("text/html; charset=utf-8")
3839
const text = await resp.text();
3940
expect(text).to.contain('This is my static 404 page');
4041
});

0 commit comments

Comments
 (0)