summaryrefslogtreecommitdiff
path: root/packages/integrations/netlify/src/netlify-edge-functions.ts
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2023-08-01 09:52:16 -0500
committerGravatar GitHub <noreply@github.com> 2023-08-01 09:52:16 -0500
commit298dbb89f2963a547370b6e65cafd2650fdb1b27 (patch)
tree6650c12dc5985f5d700319b3fc4a3826fbc40070 /packages/integrations/netlify/src/netlify-edge-functions.ts
parent0b8375fe82a15bfff3f517f98de6454adb2779f1 (diff)
downloadastro-298dbb89f2963a547370b6e65cafd2650fdb1b27.tar.gz
astro-298dbb89f2963a547370b6e65cafd2650fdb1b27.tar.zst
astro-298dbb89f2963a547370b6e65cafd2650fdb1b27.zip
Refactor 404 and 500 approach (#7754)
* fix(app): refactor 404 and 500 approach * chore: refactor logic * fix: always treat error as page * test: migrate ssr-prerender-404 to node adapter * feat: merge original response metadata with error response * chore: update lockfile * chore: trigger ci * chore(lint): fix lint issue * fix: ensure merged request has proper status * fix(node): prerender test * chore: update test label * fix(node): improve 404 behavior in middleware mode * fix(vercel): improve 404 behavior * fix(netlify): improve 404 behavior * chore: update test labels * chore: force ci * chore: fix lint * fix: avoid infinite loops * test: fix failing test in Node 18 * chore: remove volta
Diffstat (limited to 'packages/integrations/netlify/src/netlify-edge-functions.ts')
-rw-r--r--packages/integrations/netlify/src/netlify-edge-functions.ts28
1 files changed, 11 insertions, 17 deletions
diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts
index 4a6d3674c..3897a5120 100644
--- a/packages/integrations/netlify/src/netlify-edge-functions.ts
+++ b/packages/integrations/netlify/src/netlify-edge-functions.ts
@@ -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 };