Skip to content

Commit

Permalink
fix(api-server): Preserve original host header for proxied API reques…
Browse files Browse the repository at this point in the history
…ts (#10082)

Co-authored-by: Daniel Choudhury <[email protected]>
  • Loading branch information
magJ and dac09 authored Mar 7, 2024
1 parent 67df472 commit 5c8d77f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# CHANGELOG

## Unreleased
- fix(api-server): Preserve original host header for proxied API requests
Some apps rely on reading the host header(eg multi-tenant apps served over multiple subdomains). This change forwards on the original host header on proxied Fastify requests, and the experimental SSR/RSC server

- fix(deps): update prisma monorepo to v5.10.2 (#10088)

Expand Down
7 changes: 7 additions & 0 deletions packages/adapters/fastify/web/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export async function redwoodFastifyWeb(
prefix: redwoodOptions.apiUrl,
upstream: redwoodOptions.apiProxyTarget,
disableCache: true,
replyOptions: {
rewriteRequestHeaders: (req, headers) => ({
...headers,
// preserve the original host header, instead of letting it be overwritten by the proxy
host: req.headers.host,
}),
},
})
}

Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/runFeServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export async function runFeServer() {
// @WARN! Be careful, between v2 and v3 of http-proxy-middleware
// the syntax has changed https://github.com/chimurai/http-proxy-middleware
createProxyMiddleware({
changeOrigin: true,
changeOrigin: false,
pathRewrite: {
[`^${rwConfig.web.apiUrl}`]: '', // remove base path
},
Expand Down

0 comments on commit 5c8d77f

Please sign in to comment.