diff --git a/.changeset/tidy-dancers-act.md b/.changeset/tidy-dancers-act.md new file mode 100644 index 000000000000..abe7895da123 --- /dev/null +++ b/.changeset/tidy-dancers-act.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix a regression where a port was incorrectly added to the `Astro.url` diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index 87ef2a0defad..3ad965cd08c6 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -83,13 +83,12 @@ export class NodeApp extends App { const hostname = forwardedHostname ?? req.headers.host ?? req.headers[':authority']; // @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 = getFirstForwardedValue(req.headers['x-forwarded-port']); const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname); - const hostnamePort = portInHostname ? hostname : `${hostname}:${port}`; - + const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ''}`; + + const url = `${protocol}://${hostnamePort}${req.url}`; const options: RequestInit = { method: req.method || 'GET',