mirror of
https://github.com/withastro/astro.git
synced 2025-03-31 23:31:30 -05:00
fix(node): Safely create requests (#10285)
* fix(node): Wrap request creation in try catch * chore: changeset
This commit is contained in:
parent
afd41cc28b
commit
d5277df5a4
2 changed files with 14 additions and 1 deletions
5
.changeset/perfect-poets-teach.md
Normal file
5
.changeset/perfect-poets-teach.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/node": patch
|
||||
---
|
||||
|
||||
Fixes an issue where malformed requests could cause the server to error in certain cases.
|
|
@ -8,7 +8,15 @@ import type { RequestHandler } from './types.js';
|
|||
*/
|
||||
export function createAppHandler(app: NodeApp): RequestHandler {
|
||||
return async (req, res, next, locals) => {
|
||||
const request = NodeApp.createRequest(req);
|
||||
let request;
|
||||
try {
|
||||
request = NodeApp.createRequest(req);
|
||||
} catch (err) {
|
||||
res.statusCode = 500;
|
||||
res.end('Internal Server Error');
|
||||
return;
|
||||
}
|
||||
|
||||
const routeData = app.match(request);
|
||||
if (routeData) {
|
||||
const response = await app.render(request, {
|
||||
|
|
Loading…
Add table
Reference in a new issue