From 57c1dfb6c66336bdd1aab5f67970380cd9fa28d8 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 29 Jun 2023 13:46:21 -0400 Subject: [PATCH 1/2] don't check for address header until getClientAddress is called --- packages/adapter-node/src/handler.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/adapter-node/src/handler.js b/packages/adapter-node/src/handler.js index 8a1390a78f25..bae1854bdd7e 100644 --- a/packages/adapter-node/src/handler.js +++ b/packages/adapter-node/src/handler.js @@ -91,20 +91,20 @@ const ssr = async (req, res) => { return; } - if (address_header && !(address_header in req.headers)) { - throw new Error( - `Address header was specified with ${ - ENV_PREFIX + 'ADDRESS_HEADER' - }=${address_header} but is absent from request` - ); - } - setResponse( res, await server.respond(request, { platform: { req }, getClientAddress: () => { if (address_header) { + if (!(address_header in req.headers)) { + throw new Error( + `Address header was specified with ${ + ENV_PREFIX + 'ADDRESS_HEADER' + }=${address_header} but is absent from request` + ); + } + const value = /** @type {string} */ (req.headers[address_header]) || ''; if (address_header === 'x-forwarded-for') { From 94b03c1c44ea4ee348b650c40de5252591897357 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 29 Jun 2023 14:45:14 -0400 Subject: [PATCH 2/2] add changeset --- .changeset/funny-brooms-fold.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-brooms-fold.md diff --git a/.changeset/funny-brooms-fold.md b/.changeset/funny-brooms-fold.md new file mode 100644 index 000000000000..d4193bbc90e1 --- /dev/null +++ b/.changeset/funny-brooms-fold.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-node': patch +--- + +fix: do not crash server if specified `ADDRESS_HEADER` is missing from a request