From 0a28718aaad27dc9afcd08d3156a325db470d3eb Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Wed, 14 Oct 2020 01:35:38 -0400 Subject: [PATCH] Fix: x-forwarded-host is undefined on Netlify --- lib/templates/netlifyFunction.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/templates/netlifyFunction.js b/lib/templates/netlifyFunction.js index 15a7da8..222c0d9 100644 --- a/lib/templates/netlifyFunction.js +++ b/lib/templates/netlifyFunction.js @@ -31,6 +31,12 @@ exports.handler = (event, context, callback) => { process.env.BINARY_SUPPORT = "yes"; } + // x-forwarded-host is undefined on Netlify for proxied apps that need it + // fixes https://github.com/netlify/next-on-netlify/issues/46 + if (!event.multiValueHeaders.hasOwnProperty("x-forwarded-host")) { + event.multiValueHeaders["x-forwarded-host"] = [event.headers["host"]]; + } + // Get the request URL const { path } = event; console.log("[request]", path);