Skip to content

Commit

Permalink
Refactor 404 and 500 approach (#7754)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
natemoo-re authored Aug 1, 2023
1 parent e131a74 commit 8c5a6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
20 changes: 7 additions & 13 deletions packages/integrations/vercel/src/edge/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,15 @@ export function createExports(manifest: SSRManifest) {
const app = new App(manifest);

const handler = async (request: Request): Promise<Response> => {
if (app.match(request)) {
Reflect.set(request, clientAddressSymbol, request.headers.get('x-forwarded-for'));
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);
Reflect.set(request, clientAddressSymbol, request.headers.get('x-forwarded-for'));
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
7 changes: 1 addition & 6 deletions packages/integrations/vercel/src/serverless/entrypoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ export const createExports = (manifest: SSRManifest) => {
return res.end(err.reason || 'Invalid request body');
}

let routeData = app.match(request, { matchNotFound: true });
if (!routeData) {
res.statusCode = 404;
return res.end('Not found');
}

let routeData = app.match(request);
let locals = {};
if (request.headers.has(ASTRO_LOCALS_HEADER)) {
let localsAsString = request.headers.get(ASTRO_LOCALS_HEADER);
Expand Down

0 comments on commit 8c5a6c9

Please sign in to comment.