Skip to content

Commit

Permalink
fix: check if socket address/port/family are set (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Jun 14, 2022
1 parent e24ccaa commit 8fb3ad9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/dev/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ export function createDevServer (nitro: Nitro): NitroDevServer {
const proxy = httpProxy.createProxy()
proxy.on('proxyReq', (proxyReq, req) => {
// TODO: Avoid overwriting headers if already set
proxyReq.setHeader('X-Forwarded-For', req.socket.remoteAddress)
proxyReq.setHeader('X-Forwarded-Port', req.socket.remotePort)
proxyReq.setHeader('X-Forwarded-Proto', req.socket.remoteFamily)
if (req.socket.remoteAddress) {
proxyReq.setHeader('X-Forwarded-For', req.socket.remoteAddress)
}
if (req.socket.remotePort) {
proxyReq.setHeader('X-Forwarded-Port', req.socket.remotePort)
}
if (req.socket.remoteFamily) {
proxyReq.setHeader('X-Forwarded-Proto', req.socket.remoteFamily)
}
})
app.use(eventHandler(async (event) => {
await reloadPromise
Expand Down

0 comments on commit 8fb3ad9

Please sign in to comment.