Skip to content

Commit

Permalink
fix: revert regression of port computation (#12197)
Browse files Browse the repository at this point in the history
* fix: revert regression of port computation

* revert tests failing

* address feedback

* revert logic to how it was before
  • Loading branch information
ematipico authored Oct 14, 2024
1 parent b049359 commit 2aa2dfd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-dancers-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix a regression where a port was incorrectly added to the `Astro.url`
9 changes: 4 additions & 5 deletions packages/astro/src/core/app/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 2aa2dfd

Please sign in to comment.