Skip to content

Commit 2aa2dfd

Browse files
authoredOct 14, 2024··
fix: revert regression of port computation (#12197)
* fix: revert regression of port computation * revert tests failing * address feedback * revert logic to how it was before
1 parent b049359 commit 2aa2dfd

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed
 

‎.changeset/tidy-dancers-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'astro': patch
3+
---
4+
5+
Fix a regression where a port was incorrectly added to the `Astro.url`

‎packages/astro/src/core/app/node.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,12 @@ export class NodeApp extends App {
8383
const hostname = forwardedHostname ?? req.headers.host ?? req.headers[':authority'];
8484

8585
// @example "443,8080,80" => "443"
86-
const forwardedPort = getFirstForwardedValue(req.headers['x-forwarded-port']);
87-
const port =
88-
forwardedPort ?? req.socket?.remotePort?.toString() ?? (isEncrypted ? '443' : '80');
86+
const port = getFirstForwardedValue(req.headers['x-forwarded-port']);
8987

9088
const portInHostname = typeof hostname === 'string' && /:\d+$/.test(hostname);
91-
const hostnamePort = portInHostname ? hostname : `${hostname}:${port}`;
92-
89+
const hostnamePort = portInHostname ? hostname : `${hostname}${port ? `:${port}` : ''}`;
90+
91+
9392
const url = `${protocol}://${hostnamePort}${req.url}`;
9493
const options: RequestInit = {
9594
method: req.method || 'GET',

0 commit comments

Comments
 (0)
Please sign in to comment.