mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Support the /404 route in the dev server (#128)
* Support the /404 route in the dev server * Fix status code * Formatting
This commit is contained in:
parent
3ffeb0f7b7
commit
62ddea7bb7
2 changed files with 14 additions and 3 deletions
2
examples/snowpack/package-lock.json
generated
2
examples/snowpack/package-lock.json
generated
|
@ -1014,7 +1014,7 @@
|
|||
"rollup": "^2.43.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"sass": "^1.32.8",
|
||||
"snowpack": "^3.3.2",
|
||||
"snowpack": "^3.3.4",
|
||||
"svelte": "^3.35.0",
|
||||
"tiny-glob": "^0.2.8",
|
||||
"unified": "^9.2.1",
|
||||
|
|
15
src/dev.ts
15
src/dev.ts
|
@ -34,6 +34,7 @@ export default async function dev(astroConfig: AstroConfig) {
|
|||
if (result.contentType) {
|
||||
res.setHeader('Content-Type', result.contentType);
|
||||
}
|
||||
res.statusCode = 200;
|
||||
res.write(result.contents);
|
||||
res.end();
|
||||
break;
|
||||
|
@ -43,8 +44,18 @@ export default async function dev(astroConfig: AstroConfig) {
|
|||
const reqPath = decodeURI(fullurl.pathname);
|
||||
error(logging, 'static', 'Not found', reqPath);
|
||||
res.statusCode = 404;
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end('Not Found');
|
||||
|
||||
const fourOhFourResult = await runtime.load('/404');
|
||||
if (fourOhFourResult.statusCode === 200) {
|
||||
if (fourOhFourResult.contentType) {
|
||||
res.setHeader('Content-Type', fourOhFourResult.contentType);
|
||||
}
|
||||
res.write(fourOhFourResult.contents);
|
||||
} else {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.write('Not Found');
|
||||
}
|
||||
res.end();
|
||||
break;
|
||||
}
|
||||
case 500: {
|
||||
|
|
Loading…
Reference in a new issue