0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

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
This commit is contained in:
Emanuele Stoppa 2024-10-14 09:44:39 +01:00 committed by GitHub
parent b0493596dc
commit 2aa2dfd05d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix a regression where a port was incorrectly added to the `Astro.url`

View file

@ -83,12 +83,11 @@ 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 = {