Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed targetUrl replacing localhost with 127.0.0.1 #52825

Closed
wants to merge 7 commits into from

Conversation

DuCanhGH
Copy link
Contributor

@DuCanhGH DuCanhGH commented Jul 18, 2023

What?

Relands #51887, now that it has gone stale.

This fixes the same issue as #52283, but it does that in a different way. Rather than using the provided hostname, we now use exactly what server.address() returns. So if the provided host is localhost, it will return [::1] if IPv6 is used and 127.0.0.1 if IPv4 is used, ensuring that the hostname for the proxy server is always correct.

http://::1:3000 doesn't seem to be a valid URL (browsers doesn't seem to try to resolve this URL), so this PR also changes NextURL so that it handles [::1], rather than ::1. I've also changed the message Listening on port in .next/standalone/server.js so that it displays http://[::1]:3000, rather than http://::1:3000 (this also applies for any other IPv6 hostname).

Why?

This seems to be a better solution and works with IPv6 (some OSes seem to resolve localhost to [::1] instead of 127.0.0.1).

How?

It does that by doing the aforementioned, and also handles IPv6 hostnames in next-server.ts, render-server.ts, next-swc/.../next-request-helpers.ts.

I've ensured that it works with IPv6 hostnames (such as :: and ::1), IPv4 hostnames (such as 127.0.0.1) and localhost.

@ijjk ijjk added Turbopack Related to Turbopack with Next.js. type: next labels Jul 18, 2023
@DuCanhGH DuCanhGH changed the title Removed targetUrl replacing localhost with 127.0.0.1 Removed targetUrl replacing localhost with 127.0.0.1 Jul 18, 2023
@DuCanhGH DuCanhGH closed this Jul 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Turbopack Related to Turbopack with Next.js. type: next
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants