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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 BUG: inconsistent 127.0.0.1 and localhost in dev and preview #2669

Closed
millette opened this issue Feb 27, 2022 · 5 comments
Closed

馃悰 BUG: inconsistent 127.0.0.1 and localhost in dev and preview #2669

millette opened this issue Feb 27, 2022 · 5 comments

Comments

@millette
Copy link
Contributor

What version of astro are you using?

0.23.2

What package manager are you using?

pnpm

What operating system are you using?

Linux

Describe the Bug

Running astro dev, hostname is 127.0.0.1 (and --hostname doesn't do anything) whereas astro preview the hostname is localhost (and here --hostname works as expected - but not yet document withastro/docs#165).

There's a suble difference between localhost and 127.0.0.1 depending on OS configuration (IPv4 vs IPv6, etc.)

Note that the example doesn't really help since it's a cli problem.

Link to Minimal Reproducible Example

https://stackblitz.com/github/gqaiqojag?file=package.json

@github-actions github-actions bot added this to Needs Triage in 馃悰 Bug Tracker Feb 27, 2022
@wlto
Copy link

wlto commented Feb 27, 2022

Getting a similar issue with astro dev as well. I've set localhost as the host in my config file but the CLI log still outputs [astro] Local: http://127.0.0.1:3000/.

Dig a little deeper and I believe the problem is around this line in core dev file (I'm just taking a look at the built file in dist in the boilerplate (via the npm init astro command):

CleanShot 2022-02-27 at 16 57 44@2x

The log on line 23 outputs address { address: '127.0.0.1', family: 'IPv4', port: 3000 }. So it seems like it doesn't respect the host in the Vite config for some reason.

I'm relatively new to open-source development so not sure where to go from here. But just posting my findings here in case it helps. Any insights or advice from the core team would be appreciated. I really like this project so hope I can contribute somehow 馃槃

@wlto
Copy link

wlto commented Feb 28, 2022

Was looking at the difference between the preview and dev code. And noticing that the address in core/preview/index.js is taking the hostname directly from the config file:

CleanShot 2022-02-27 at 21 50 14@2x

Does it make sense if we do something similar for core/dev/index.js?

CleanShot 2022-02-27 at 21 52 50@2x

@wlto
Copy link

wlto commented Feb 28, 2022

Some more updates. Figured it might be a Vite bug so took a look at their repo and found this PR: vitejs/vite#7092

So I'm guessing this is something related to Vite.

@wlto
Copy link

wlto commented Mar 5, 2022

Good news! The PR I linked above vitejs/vite#7092 was just merged to Vite's main branch. Hopefully we can see a new version with the fix soon :)

@FredKSchott
Copy link
Member

Woo! Closing this as an upstream issue. Also, @bholmesdev has been doing some work for v0.24.0 to have an updated CLI output with a new --host flag to match Vite's support more closely. Please try it out with npm install astro@next and report back if you have any issues!

馃悰 Bug Tracker automation moved this from Needs Triage to Done Mar 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

3 participants