summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/src/core/app/index.ts4
-rw-r--r--packages/astro/src/runtime/server/endpoint.ts8
-rw-r--r--packages/astro/src/vite-plugin-astro-server/index.ts19
-rw-r--r--packages/astro/test/ssr-404-500-pages.test.js10
4 files changed, 20 insertions, 21 deletions
diff --git a/packages/astro/src/core/app/index.ts b/packages/astro/src/core/app/index.ts
index 8149d5874..1c9f7acf3 100644
--- a/packages/astro/src/core/app/index.ts
+++ b/packages/astro/src/core/app/index.ts
@@ -202,10 +202,10 @@ export class App {
});
if (result.type === 'response') {
- if(result.response.headers.get('X-Astro-Response') === 'Not-Found') {
+ if (result.response.headers.get('X-Astro-Response') === 'Not-Found') {
const fourOhFourRequest = new Request(new URL('/404', request.url));
const fourOhFourRouteData = this.match(fourOhFourRequest);
- if(fourOhFourRouteData) {
+ if (fourOhFourRouteData) {
return this.render(fourOhFourRequest, fourOhFourRouteData);
}
}
diff --git a/packages/astro/src/runtime/server/endpoint.ts b/packages/astro/src/runtime/server/endpoint.ts
index 082290c9e..1a285bab0 100644
--- a/packages/astro/src/runtime/server/endpoint.ts
+++ b/packages/astro/src/runtime/server/endpoint.ts
@@ -18,11 +18,7 @@ function getHandlerFromModule(mod: EndpointHandler, method: string) {
}
/** Renders an endpoint request to completion, returning the body. */
-export async function renderEndpoint(
- mod: EndpointHandler,
- request: Request,
- params: Params
-) {
+export async function renderEndpoint(mod: EndpointHandler, request: Request, params: Params) {
const chosenMethod = request.method?.toLowerCase();
const handler = getHandlerFromModule(mod, chosenMethod);
if (!handler || typeof handler !== 'function') {
@@ -32,7 +28,7 @@ export async function renderEndpoint(
let response = new Response(null, {
status: 404,
headers: {
- 'X-Astro-Response': 'Not-Found'
+ 'X-Astro-Response': 'Not-Found',
},
});
return response;
diff --git a/packages/astro/src/vite-plugin-astro-server/index.ts b/packages/astro/src/vite-plugin-astro-server/index.ts
index a1448d553..188b39f70 100644
--- a/packages/astro/src/vite-plugin-astro-server/index.ts
+++ b/packages/astro/src/vite-plugin-astro-server/index.ts
@@ -1,7 +1,7 @@
import type http from 'http';
import mime from 'mime';
import type * as vite from 'vite';
-import type { AstroConfig, ManifestData, SSRManifest } from '../@types/astro';
+import type { AstroConfig, ManifestData } from '../@types/astro';
import type { SSROptions } from '../core/render/dev/index';
import { Readable } from 'stream';
@@ -28,8 +28,11 @@ interface AstroPluginOptions {
logging: LogOptions;
}
-type AsyncReturnType<T extends (...args: any) => Promise<any>> =
- T extends (...args: any) => Promise<infer R> ? R : any
+type AsyncReturnType<T extends (...args: any) => Promise<any>> = T extends (
+ ...args: any
+) => Promise<infer R>
+ ? R
+ : any;
function writeHtmlResponse(res: http.ServerResponse, statusCode: number, html: string) {
res.writeHead(statusCode, {
@@ -181,7 +184,7 @@ async function matchRoute(
viteServer: vite.ViteDevServer,
logging: LogOptions,
manifest: ManifestData,
- config: AstroConfig,
+ config: AstroConfig
) {
const matches = matchAllRoutes(pathname, manifest);
@@ -273,7 +276,7 @@ async function handleRequest(
if (!(req.method === 'GET' || req.method === 'HEAD')) {
let bytes: Uint8Array[] = [];
await new Promise((resolve) => {
- req.on('data', part => {
+ req.on('data', (part) => {
bytes.push(part);
});
req.on('end', resolve);
@@ -292,7 +295,7 @@ async function handleRequest(
config
);
filePath = matchedRoute?.filePath;
-
+
return await handleRoute(
matchedRoute,
url,
@@ -307,7 +310,7 @@ async function handleRequest(
req,
res
);
- } catch(_err) {
+ } catch (_err) {
const err = fixViteErrorMessage(_err, viteServer, filePath);
const errorWithMetadata = collectErrorMetadata(err);
error(logging, null, msg.formatErrorMessage(errorWithMetadata));
@@ -376,7 +379,7 @@ async function handleRoute(
if (route.type === 'endpoint') {
const result = await callEndpoint(options);
if (result.type === 'response') {
- if(result.response.headers.get('X-Astro-Response') === 'Not-Found') {
+ if (result.response.headers.get('X-Astro-Response') === 'Not-Found') {
const fourOhFourRoute = await matchRoute(
'/404',
routeCache,
diff --git a/packages/astro/test/ssr-404-500-pages.test.js b/packages/astro/test/ssr-404-500-pages.test.js
index 2d56ef2f8..2216aa762 100644
--- a/packages/astro/test/ssr-404-500-pages.test.js
+++ b/packages/astro/test/ssr-404-500-pages.test.js
@@ -28,14 +28,14 @@ describe('404 and 500 pages', () => {
it('Returns 404 when hitting an API route with the wrong method', async () => {
let res = await fixture.fetch('/api/route', {
- method: 'PUT'
+ method: 'PUT',
});
let html = await res.text();
let $ = cheerio.load(html);
expect($('h1').text()).to.equal(`Something went horribly wrong!`);
});
});
-
+
describe('Production', () => {
before(async () => {
await fixture.build({});
@@ -50,7 +50,7 @@ describe('404 and 500 pages', () => {
const $ = cheerio.load(html);
expect($('h1').text()).to.equal('Something went horribly wrong!');
});
-
+
it('404 page returned when a route does not match and passing routeData', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/some/fake/route');
@@ -61,7 +61,7 @@ describe('404 and 500 pages', () => {
const $ = cheerio.load(html);
expect($('h1').text()).to.equal('Something went horribly wrong!');
});
-
+
it('500 page returned when there is an error', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/causes-error');
@@ -75,7 +75,7 @@ describe('404 and 500 pages', () => {
it('Returns 404 when hitting an API route with the wrong method', async () => {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com/api/route', {
- method: 'PUT'
+ method: 'PUT',
});
const response = await app.render(request);
expect(response.status).to.equal(404);