Skip to content

Commit

Permalink
fix: return 400 response if request construction fails
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jan 22, 2024
1 parent f56781f commit e49f0f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-scissors-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-node': patch
---

fix: return 400 response if request construction fails
19 changes: 14 additions & 5 deletions packages/adapter-node/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,20 @@ function serve_prerendered() {

/** @type {import('polka').Middleware} */
const ssr = async (req, res) => {
const request = await getRequest({
base: origin || get_origin(req.headers),
request: req,
bodySizeLimit: body_size_limit
});
/** @type {Request} */
let request;

try {
request = await getRequest({
base: origin || get_origin(req.headers),
request: req,
bodySizeLimit: body_size_limit
});
} catch {
res.statusCode = 400;
res.end('Bad Request');
return;
}

setResponse(
res,
Expand Down

0 comments on commit e49f0f0

Please sign in to comment.