0

I have a vue.js project created with Vue CLI and npm run serveit always run on localhost.

I want to access from my phone (another IP inside the same network), so I want the serve to run on 0.0.0.0. I tried adding the vue.config.js file and setting the host:

module.exports = {
    publicPath: '/',
    devServer: {
        host: '0.0.0.0',
        port: 8080
    }
}

Changing the port works fine, but the host override is ignored. This is the output of serve:

App running at:
  - Local:   http://localhost:8080/
  - Network: http://192.168.0.21:8080/

At first I thought it was being ignored, so I tried setting the host to 0.0.0.1 and the output is "correct", so the file is not ignored, only the 0.0.0.0 is being changed to localhost:

  App running at:
  - Local:   http://0.0.0.1:8080/
  - Network: http://0.0.0.1:8080/

I saw in some forums that devServer has a public option to set the URL, but if I try setting pubic: 'http://0.0.0.0:8080/' I get an error:

> npm run serve
Debugger attached.

> [email protected] serve <my project path>
> vue-cli-service serve

Debugger attached.
 INFO  Starting development server...
 ERROR  ValidationError: webpack Dev Server Invalid Options

options should NOT have additional properties

ValidationError: webpack Dev Server Invalid Options

options should NOT have additional properties

I need to run the server on 0.0.0.0 so I can test it on my phone.

Any help will be very appreciated.

1 Answer 1

1

You shouldn't need to run it on 0.0.0.0 from your local machine to test it on your phone. As long as the port on which it's running is open to external traffic and your phone is connected to your LAN via wifi, you can just put the IP address of your computer and the port # in as the URL.

Sign up to request clarification or add additional context in comments.

3 Comments

I already tried connecting to http://192.168.0.21:8080/ from the phone as you suggested, but it didn't work. Also, I don't get why I should need the port open to external traffic if the phone is in my LAN via wifi, but I'll try that.
Just open port 8080 on your computer's firewall.
ok, this fixed it for me, thanks a lot! Although, I still don't get why I couldn't run vue on 0.0.0.0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.