Skip to content

Commit

Permalink
fix(node): Safely create requests (#10285)
Browse files Browse the repository at this point in the history
* fix(node): Wrap request creation in try catch

* chore: changeset
  • Loading branch information
Princesseuh authored Mar 1, 2024
1 parent afd41cc commit d5277df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/perfect-poets-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/node": patch
---

Fixes an issue where malformed requests could cause the server to error in certain cases.
10 changes: 9 additions & 1 deletion packages/integrations/node/src/serve-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit d5277df

Please sign in to comment.