question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

host 0.0.0.0 setting do not work in production mode

See original GitHub issue

Environment

  • Operating System: Windows_NT
  • Node Version: v14.16.0
  • Nuxt Version: 3.0.0-27319101.3e82f0f
  • Package Manager: yarn@1.22.17
  • Bundler: Vite
  • User Config: buildModules, css, privateRuntimeConfig, meta, vite, build
  • Runtime Modules: -
  • Build Modules: nuxt-windicss@2.1.1, @intlify/nuxt3@0.1.9

Reproduction

nuxt.config.js

import { defineNuxtConfig } from 'nuxt3'

export default defineNuxtConfig({
    ...,
    vite: {
        server: {
            host: '0.0.0.0'
        }
    }
})

Describe the bug

When I run yarn dev, it works as I expect:

> Local:    http://localhost:5555/
> Network:  http://xxx.xxx.x.xxx:5555/

But when running yarn build & yarn start: I can only access http://localhost:3000/

Listening on http://localhost:3000

I’m not sure is that a bug or not. Or, is there any way to access the public address in production mode?

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
banlifycommented, Dec 30, 2021

Hi @K-Honkawa , I set HOST and PORT to .env but it still runs on port 3000.

.env :

NUXT_HOST=0.0.0.0
HOST=0.0.0.0
NUXT_PORT=4000
PORT=4000

Running yarn dev :

Nuxt CLI v3.0.0-27335375.b41a1d2

  > Local:    http://localhost:3000/ 
  > Network:  http://192.168.1.2:3000/
  > Network:  http://10.3.1.2:3000/

Running yarn build then yarn start :

yarn run v1.22.17
$ node .output/server/index.mjs
Listening on http://localhost:3000

What is expected :

Running yarn dev :

Nuxt CLI v3.0.0-27335375.b41a1d2

  > Local:    http://localhost:4000/ 
  > Network:  http://192.168.1.2:4000/
  > Network:  http://10.3.1.2:4000/

Running yarn build then yarn start :

yarn run v1.22.17
$ node .output/server/index.mjs
Listening on http://localhost:4000

Any help is appreciated.

  1. install cross-env pkg.
npm i cross-env -D
  1. package.json
{
  "scripts": {
    "dev": "nuxi dev --host 0.0.0.0",
    "build": "nuxi build",
    "start": "cross-env HOST=0.0.0.0 cross-env PORT=5000 node .output/server/index.mjs"
}
3reactions
chenej9797commented, Dec 28, 2021

Hi, @kevinadhiguna. I don’t know how to set Nuxt env in the most correct way. But maybe you can try this one:

.env

NUXT_HOST=0.0.0.0
NUXT_PORT=4000

package.json

...
"scripts": {
    "dev": "nuxi dev",
    "build": "nuxi build",
    "start": "eval $(grep '^NUXT_HOST' .env) $(grep '^NUXT_PORT' .env) node .output/server/index.mjs"
 }
...

It works for me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flask not able to run on 0.0.0.0 - Stack Overflow
I am not able to run Flask on host 0.0.0.0. When I run it with 0.0.0.0, it instead shows my Local IP address....
Read more >
DevServer - webpack
webpack-dev-server can be used to quickly develop an application. See the development guide to get started. This page describes the options that affect...
Read more >
Settings - Uvicorn
Settings ¶. Use the following options to configure Uvicorn, when running from the command line. If you're running programmatically, using uvicorn.run(.
Read more >
Configure endpoints for the ASP.NET Core Kestrel web server
If no ports are specified, Kestrel binds to http://localhost:5000 . ... For SNI to function, the client sends the host name for the...
Read more >
Quickstart — Flask Documentation (2.2.x)
flask run --host=0.0.0.0 ... Do not run the development server or debugger in a production environment. To enable debug mode, use the --debug...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found