From 1270d4d63ea9ed6fdd99b21ce417ab097876555b Mon Sep 17 00:00:00 2001 From: bluwy Date: Tue, 1 Aug 2023 14:55:54 +0000 Subject: [PATCH] [ci] format --- packages/astro/src/core/app/index.ts | 29 +++++++++++++------ .../netlify/src/netlify-edge-functions.ts | 2 +- .../node/test/node-middleware.test.js | 6 ++-- .../node/test/prerender-404.test.js | 4 ++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts index 5fdbf9472..37c972287 100644 --- a/packages/astro/src/core/app/index.ts +++ b/packages/astro/src/core/app/index.ts @@ -40,7 +40,7 @@ export interface MatchOptions { matchNotFound?: boolean | undefined; } export interface RenderErrorOptions { - routeData?: RouteData; + routeData?: RouteData; response?: Response; status: 404 | 500; } @@ -170,14 +170,22 @@ export class App { if (isResponse(response, routeData.type)) { if (STATUS_CODES.has(response.status)) { - return this.#renderError(request, { routeData, response, status: response.status as 404 | 500 } ); + return this.#renderError(request, { + routeData, + response, + status: response.status as 404 | 500, + }); } Reflect.set(response, responseSentSymbol, true); return response; } else { if (response.type === 'response') { if (response.response.headers.get('X-Astro-Response') === 'Not-Found') { - return this.#renderError(request, { routeData, response: response.response, status: 404 }); + return this.#renderError(request, { + routeData, + response: response.response, + status: 404, + }); } return response.response; } else { @@ -268,7 +276,10 @@ export class App { * If is a known error code, try sending the according page (e.g. 404.astro / 500.astro). * This also handles pre-rendered /404 or /500 routes */ - async #renderError(request: Request, { routeData, status, response: originalResponse }: RenderErrorOptions) { + async #renderError( + request: Request, + { routeData, status, response: originalResponse }: RenderErrorOptions + ) { const errorRouteData = matchRoute('/' + status, this.#manifestData); const url = new URL(request.url); if (errorRouteData) { @@ -288,12 +299,12 @@ export class App { status ); const page = (await mod.page()) as any; - const response = await tryRenderRoute( + const response = (await tryRenderRoute( 'page', // this is hardcoded to ensure proper behavior for missing endpoints newRenderContext, this.#env, page - ) as Response; + )) as Response; return this.#mergeResponses(response, originalResponse); } catch {} } @@ -310,12 +321,12 @@ export class App { return new Response(newResponse.body, { status: status === 200 ? newResponse.status : status, statusText, - headers: new Headers(Array.from(headers)) - }) + headers: new Headers(Array.from(headers)), + }); } #getDefaultStatusCode(route: string): number { - route = removeTrailingForwardSlash(route) + route = removeTrailingForwardSlash(route); if (route.endsWith('/404')) return 404; if (route.endsWith('/500')) return 500; return 200; diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts index 3897a5120..5e95035a6 100644 --- a/packages/integrations/netlify/src/netlify-edge-functions.ts +++ b/packages/integrations/netlify/src/netlify-edge-functions.ts @@ -15,7 +15,7 @@ export function createExports(manifest: SSRManifest) { if (manifest.assets.has(url.pathname)) { return; } - const routeData = app.match(request) + const routeData = app.match(request); const ip = request.headers.get('x-nf-client-connection-ip') || context?.ip || diff --git a/packages/integrations/node/test/node-middleware.test.js b/packages/integrations/node/test/node-middleware.test.js index 350e48c7a..d7ba79e4c 100644 --- a/packages/integrations/node/test/node-middleware.test.js +++ b/packages/integrations/node/test/node-middleware.test.js @@ -8,7 +8,9 @@ import * as cheerio from 'cheerio'; */ async function load() { - const mod = await import(`./fixtures/node-middleware/dist/server/entry.mjs?dropcache=${Date.now()}`); + const mod = await import( + `./fixtures/node-middleware/dist/server/entry.mjs?dropcache=${Date.now()}` + ); return mod; } @@ -35,7 +37,7 @@ describe('behavior from middleware', () => { await server.stop(); await fixture.clean(); delete process.env.PRERENDER; - }) + }); describe('404', async () => { it('when mode is standalone', async () => { diff --git a/packages/integrations/node/test/prerender-404.test.js b/packages/integrations/node/test/prerender-404.test.js index df36fa414..626f584e0 100644 --- a/packages/integrations/node/test/prerender-404.test.js +++ b/packages/integrations/node/test/prerender-404.test.js @@ -9,7 +9,9 @@ import { fetch } from 'undici'; */ async function load() { - const mod = await import(`./fixtures/prerender-404/dist/server/entry.mjs?dropcache=${Date.now()}`); + const mod = await import( + `./fixtures/prerender-404/dist/server/entry.mjs?dropcache=${Date.now()}` + ); return mod; } describe('Prerender 404', () => {