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

Astro preview --host doesn't work as expected #13034

Closed
1 task
Antonytm opened this issue Jan 21, 2025 · 5 comments · Fixed by withastro/adapters#514
Closed
1 task

Astro preview --host doesn't work as expected #13034

Antonytm opened this issue Jan 21, 2025 · 5 comments · Fixed by withastro/adapters#514
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: node Related to Node adapter (scope)

Comments

@Antonytm
Copy link

Antonytm commented Jan 21, 2025

Astro Info

Astro                    v5.1.8
Node                     v20.12.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/react

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

Any browser

Describe the Bug

I want to run astro preview and make it available on all IP addresses.

I tried npm run astro preview --host and I tried astro.config.mjs server>host set to true.

e.g. for astro preview --host I get:

20:30:34 [@astrojs/node] Server listening on
  local: http://localhost:3000
  network: http://192.168.88.23:3000

And if I try to open http://192.168.88.23:3000 in browser, I get nothing.

But if I run astro dev --host, I have different results:

 astro  v5.1.8 ready in 332 ms

┃ Local    http://localhost:3000/
┃ Network  http://192.168.88.23:3000/
           http://172.23.96.1:3000/
           http://172.19.176.1:3000/

And any IP address is available from the browser.

What's the expected result?

Ability to use astro preview with --host flag in the same way as astro dev

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-rnmmfmc9?file=package.json,astro.config.mjs&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.

Added details

The issue is only reproducible with astrojs/node adapter. Sample astro configuration:

// @ts-check
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';

// https://astro.build/config
export default defineConfig({
  server: {
    host: true,
  },
  output: 'server',
  adapter: node({
    mode: 'standalone',
  }),
});

@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 21, 2025
@hel-b
Copy link

hel-b commented Jan 22, 2025

Hi, I am experiencing the same issue with Astro V5. If you are in a pinch and need to preview your build locally, running entry.mjs worked for me:

$ HOST=0.0.0.0 PORT=3000 node ./dist/server/entry.mjs

@ascorbic
Copy link
Contributor

ascorbic commented Jan 22, 2025

I can't reproduce this. I downloaded your Stackblitz reproduction (it won't work in Stackblitz because it's not real networking) and ran it locally, unchanged and this was the result:

Image

That shows both of my network connections, and is the same as when running dev. Can you confirm that the Stackblitz reproduction give that result for you locally too? If so maybe it's Windows, as I'm on a Mac

@ascorbic ascorbic added needs response Issue needs response from OP and removed needs triage Issue needs to be triaged labels Jan 22, 2025
@Antonytm
Copy link
Author

Hi, I am experiencing the same issue with Astro V5. If you are in a pinch and need to preview your build locally, running entry.mjs worked for me:

$ HOST=0.0.0.0 PORT=3000 node ./dist/server/entry.mjs

I appreciate your suggestion of this option.
Unfortunately, I run Astro in an environment that I don't control. IP could differ from time to time.
The option that I consider now, is some proxy node app. It will get an available IP address and use it to start node ./dist/server/entry.mjs. But that is what actually astro preview --host should do...

@Antonytm
Copy link
Author

I can't reproduce this. I downloaded your Stackblitz reproduction (it won't work in Stackblitz because it's not real networking) and ran it locally, unchanged and this was the result:

Image

That shows both of my network connections, and is the same as when running dev. Can you confirm that the Stackblitz reproduction give that result for you locally too? If so maybe it's Windows, as I'm on a Mac

I have updated StackBlitz. The one thing that differs from local reproduction was missed: @astrojs/node adapter.
Now, I can confirm that the issue is reproducible on the project from StackBlitz.

Image

The big problem is that even preview says that website is now available on http://192.168.88.23:4321/, it is not. This site can’t be reached 192.168.88.23 refused to connect.

The dev mode works fine. All listed IP addresses are available in the browser.

@ascorbic
Copy link
Contributor

OK, thanks. I have a fix.

@ascorbic ascorbic added pkg: node Related to Node adapter (scope) - P3: minor bug An edge case that only affects very specific usage (priority) and removed needs response Issue needs response from OP labels Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) pkg: node Related to Node adapter (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants