diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 8dd312760f..87ef2a0def 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -84,10 +84,11 @@ export class NodeApp extends App { // @example "443,8080,80" => "443" const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']); - const port = forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80'); + const port = + forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80'); const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname); - const hostnamePort = portInHostname ? hostname : `${hostname}:${port}` + const hostnamePort = portInHostname ? hostname : `${hostname}:${port}`; const url = `${protocol}://${hostnamePort}${req.url}`; const options: RequestInit = { @@ -105,7 +106,7 @@ export class NodeApp extends App { // @example "1.1.1.1,8.8.8.8" => "1.1.1.1" const forwardedClientIp = getFirstForwardedValue(req.headers['x-forwarded-for']); const clientIp = forwardedClientIp || req.socket?.remoteAddress; - if (clientIp) { + if (clientIp) { Reflect.set(request, clientAddressSymbol, clientIp); } diff --git a/packages/astro/test/units/app/node.test.js b/packages/astro/test/units/app/node.test.js index 06065406ed..d11a0a8aa0 100644 --- a/packages/astro/test/units/app/node.test.js +++ b/packages/astro/test/units/app/node.test.js @@ -158,7 +158,6 @@ describe('NodeApp', () => { assert.equal(result.url, 'https://example.com:3000/'); }); - it('prefers port from x-forwarded-host', () => { const result = NodeApp.createRequest({ ...mockNodeRequest,