[ci] format
This commit is contained in:
parent
886965d354
commit
1270d4d63e
4 changed files with 28 additions and 13 deletions
|
@ -170,14 +170,22 @@ export class App {
|
||||||
|
|
||||||
if (isResponse(response, routeData.type)) {
|
if (isResponse(response, routeData.type)) {
|
||||||
if (STATUS_CODES.has(response.status)) {
|
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);
|
Reflect.set(response, responseSentSymbol, true);
|
||||||
return response;
|
return response;
|
||||||
} else {
|
} else {
|
||||||
if (response.type === 'response') {
|
if (response.type === 'response') {
|
||||||
if (response.response.headers.get('X-Astro-Response') === 'Not-Found') {
|
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;
|
return response.response;
|
||||||
} else {
|
} 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).
|
* 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
|
* 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 errorRouteData = matchRoute('/' + status, this.#manifestData);
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
if (errorRouteData) {
|
if (errorRouteData) {
|
||||||
|
@ -288,12 +299,12 @@ export class App {
|
||||||
status
|
status
|
||||||
);
|
);
|
||||||
const page = (await mod.page()) as any;
|
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
|
'page', // this is hardcoded to ensure proper behavior for missing endpoints
|
||||||
newRenderContext,
|
newRenderContext,
|
||||||
this.#env,
|
this.#env,
|
||||||
page
|
page
|
||||||
) as Response;
|
)) as Response;
|
||||||
return this.#mergeResponses(response, originalResponse);
|
return this.#mergeResponses(response, originalResponse);
|
||||||
} catch {}
|
} catch {}
|
||||||
}
|
}
|
||||||
|
@ -310,12 +321,12 @@ export class App {
|
||||||
return new Response(newResponse.body, {
|
return new Response(newResponse.body, {
|
||||||
status: status === 200 ? newResponse.status : status,
|
status: status === 200 ? newResponse.status : status,
|
||||||
statusText,
|
statusText,
|
||||||
headers: new Headers(Array.from(headers))
|
headers: new Headers(Array.from(headers)),
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#getDefaultStatusCode(route: string): number {
|
#getDefaultStatusCode(route: string): number {
|
||||||
route = removeTrailingForwardSlash(route)
|
route = removeTrailingForwardSlash(route);
|
||||||
if (route.endsWith('/404')) return 404;
|
if (route.endsWith('/404')) return 404;
|
||||||
if (route.endsWith('/500')) return 500;
|
if (route.endsWith('/500')) return 500;
|
||||||
return 200;
|
return 200;
|
||||||
|
|
|
@ -15,7 +15,7 @@ export function createExports(manifest: SSRManifest) {
|
||||||
if (manifest.assets.has(url.pathname)) {
|
if (manifest.assets.has(url.pathname)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const routeData = app.match(request)
|
const routeData = app.match(request);
|
||||||
const ip =
|
const ip =
|
||||||
request.headers.get('x-nf-client-connection-ip') ||
|
request.headers.get('x-nf-client-connection-ip') ||
|
||||||
context?.ip ||
|
context?.ip ||
|
||||||
|
|
|
@ -8,7 +8,9 @@ import * as cheerio from 'cheerio';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function load() {
|
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;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +37,7 @@ describe('behavior from middleware', () => {
|
||||||
await server.stop();
|
await server.stop();
|
||||||
await fixture.clean();
|
await fixture.clean();
|
||||||
delete process.env.PRERENDER;
|
delete process.env.PRERENDER;
|
||||||
})
|
});
|
||||||
|
|
||||||
describe('404', async () => {
|
describe('404', async () => {
|
||||||
it('when mode is standalone', async () => {
|
it('when mode is standalone', async () => {
|
||||||
|
|
|
@ -9,7 +9,9 @@ import { fetch } from 'undici';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async function load() {
|
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;
|
return mod;
|
||||||
}
|
}
|
||||||
describe('Prerender 404', () => {
|
describe('Prerender 404', () => {
|
||||||
|
|
Loading…
Reference in a new issue