Skip to content

Commit

Permalink
fix(netlify): improve 404 behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Jul 24, 2023
1 parent fd85aab commit cf9fcf0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
1 change: 1 addition & 0 deletions .changeset/rich-toys-jog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---
'@astrojs/netlify': patch
'@astrojs/vercel': patch
---

Expand Down
28 changes: 11 additions & 17 deletions packages/integrations/netlify/src/netlify-edge-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,19 @@ export function createExports(manifest: SSRManifest) {
if (manifest.assets.has(url.pathname)) {
return;
}
if (app.match(request)) {
const ip =
request.headers.get('x-nf-client-connection-ip') ||
context?.ip ||
(context as any)?.remoteAddr?.hostname;
Reflect.set(request, clientAddressSymbol, ip);
const response = await app.render(request);
if (app.setCookieHeaders) {
for (const setCookieHeader of app.setCookieHeaders(response)) {
response.headers.append('Set-Cookie', setCookieHeader);
}
const routeData = app.match(request)
const ip =
request.headers.get('x-nf-client-connection-ip') ||
context?.ip ||
(context as any)?.remoteAddr?.hostname;
Reflect.set(request, clientAddressSymbol, ip);
const response = await app.render(request, routeData);
if (app.setCookieHeaders) {
for (const setCookieHeader of app.setCookieHeaders(response)) {
response.headers.append('Set-Cookie', setCookieHeader);
}
return response;
}

return new Response(null, {
status: 404,
statusText: 'Not found',
});
return response;
};

return { default: handler };
Expand Down
10 changes: 1 addition & 9 deletions packages/integrations/netlify/src/netlify-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,7 @@ export const createExports = (manifest: SSRManifest, args: Args) => {
}
const request = new Request(rawUrl, init);

let routeData = app.match(request, { matchNotFound: true });

if (!routeData) {
return {
statusCode: 404,
body: 'Not found',
};
}

const routeData = app.match(request);
const ip = headers['x-nf-client-connection-ip'];
Reflect.set(request, clientAddressSymbol, ip);
let locals = {};
Expand Down

0 comments on commit cf9fcf0

Please sign in to comment.