withastro / astro

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

`--host` on npm doesn't expose development server #9686

Closed ghost closed 10 months ago

ghost commented 10 months ago

Astro Info

Astro                    v4.1.2
Node                     v21.5.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind

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

No response

Describe the Bug

When I run npm run dev -- --host (or npm run dev --host), the development server is not exposed.

PS C:\Users\XXXXX\Desktop\XXXXX> npm run dev -- --host

> XXXXX@0.0.1 dev
> astro dev

 astro  v4.1.2 ready in 662 ms

┃ Local    http://localhost:4321/
┃ Network  use --host to expose

What's the expected result?

I expect it to expose the development server to my network and output the IPs that it's on.

Link to Minimal Reproducible Example

Not applicable.

Participation

mandar1jn commented 10 months ago

Discussion around this issue can be found on discord. Issue verified by Dreyfus

TheElegantCoding commented 10 months ago

same here preview and server options are not working

import sitemap from '@astrojs/sitemap';
import { defineConfig } from 'astro/config';
import { loadEnv } from 'vite';

const environment = loadEnv(process.env.NODE_ENV ?? 'development', './src/global/env', '');

export default defineConfig({
  build:
  {
    assetsPrefix: process.env.NODE_ENV === 'production' ? environment.BASE_URL : undefined,
    inlineStylesheets: 'never'
  },
  integrations: [ sitemap() ],
  site: environment.BASE_URL,
  vite:
  {
    envDir: './src/global/env',
    preview:
    {
      host: true,
      open: true
    },
    server:
    {
      host: true,
      open: true
    }
  }
});

Here is the repo for reproduction Astro template

ruohki commented 10 months ago
> strong-star@0.0.1 astro
> astro info

Astro                    v4.1.2
Node                     v18.16.1
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/node
Integrations             @astrojs/tailwind
> strong-star@0.0.1 astro
> astro dev --host

 astro  v4.1.2 ready in 427 ms

┃ Local    http://localhost:4321/
┃ Network  http://172.17.112.1:4321/
           http://192.168.45.1:4321/
           http://192.168.249.1:4321/
           http://10.25.94.237:4321/

Running node 18 here — since it's windows, maybe a UAC issue?

ematipico commented 10 months ago

I can't replicate the issue, although the script works when using npm run dev -- --host. Using npm run dev --host won't work.

TheElegantCoding commented 10 months ago

@ematipico and using the astro config file works for you ?

ematipico commented 10 months ago

@ematipico and using the astro config file works for you ?

If you mean vite.server.host, no, it doesn't. Although I think should be a separate issue.

TheElegantCoding commented 10 months ago

in that case i will open other issue

ghost commented 10 months ago

I'm not using Vite (or anything similar) though. This is my config:

import { defineConfig } from 'astro/config';

import tailwind from "@astrojs/tailwind";

// https://astro.build/config
export default defineConfig({
  integrations: [tailwind()]
});
Astro                    v4.2.3
Node                     v21.5.0
System                   Windows (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/tailwind

Updated to v4.2.3, issue still occurring. Tried to make a reproducible instance with Stackblitz but I think it's set to disallow --host.

luckman212 commented 5 months ago

Thanks.

npm run dev -- --host did the trick for me 🚀

ruohki commented 4 months ago

Thanks.

npm run dev -- --host did the trick for me 🚀

Yeah if you miss the first -- you are passing the --host to npm rather than the astro command that is behind run dev