withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.27k stars 2.44k forks source link

PORT in URL address in production (Astro.url) #12192

Closed Fakerko closed 5 days ago

Fakerko commented 1 week ago

Astro Info

Astro v4.16.0
@astrojs/node v8.3.4

Node v20.17.0

The bug is in production on domain assigned.

If this issue only occurs in one browser, which browser is a problem?

Tested in Chrome

Describe the Bug

When I call Astro.url, Astro.url.href, Astro.url.host and Astro.url.origin return the URL in the format:

http(s)://www.example.com:PORT

Which is correct in a development environment, but not in production. In a previous version of Astro, I tested Astro v4.15.7, the URL did not include PORT in production.

Reproduced code example in production: https://www.palocko.cz/test

I think it's related to: https://github.com/withastro/astro/pull/12130

What's the expected result?

In production it should not contain the PORT after domain.

So instead of http(s)://www.example.com:PORT it should be http(s)://www.example.com

As mentioned here: https://docs.astro.build/en/reference/api-reference/#astrourl

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-7rspdv?file=src%2Fpages%2Findex.astro

Participation

ematipico commented 1 week ago

Hi @Fakerko, can I ask you to try astro@experimental--astro-url-fix and report if this version fixes your app?

Fakerko commented 1 week ago

Hi @ematipico, I tried, but was not able to test it because the production environment ended on error see screenshot.

Snímek obrazovky 2024-10-11 v 16 47 59
matthewp commented 6 days ago

Hey @Fakerko, what version of Node.js are you using?

matthewp commented 6 days ago

If you do:

> new Request('http://example.com:80/url').url
'http://example.com/url'

The port gets stripped when you call new Request. I tried in several versions of Node and always saw that. Given that, I'm not sure how it's possible that https://github.com/withastro/astro/commit/e96bcae535ef2f0661f539c1d49690c531df2d4e is the cause of this bug.

Fakerko commented 6 days ago

@matthewp Hi, I am using v20.17.0 on the production server.

The problem is that I didn't edit anything on the site, I only updated from Astro version 4.15.7 to 4.16.0 and the URLs were wrong.

Fakerko commented 6 days ago

@matthewp Just tested, that the last working version is Astro v4.15.12. After update to v4.16.0 or v4.16.2 the problem appear.

Fakerko commented 6 days ago

@matthewp I disabled cache on the site https://www.palocko.cz/test do you see the port is changing every time on page reload? I think this is not normal.

ematipico commented 5 days ago

@Fakerko we just released a patch (v4.16.3) that should fix your regression. Could you please test it and report back to us?

Fakerko commented 5 days ago

@ematipico It fixed the issue! Working as expected now. Thank you.

matthewp commented 4 days ago

@Fakerko what port number were you seeing?

Fakerko commented 4 days ago

@matthewp Now I don't see any port anymore. Before I always saw a random 5 digit port.