vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.75k stars 6.33k forks source link

`vue-cli-service serve` displays `localhost:<port message>` when running in a container even when `devServer.public` is set #4595

Open BenjaminNolan opened 5 years ago

BenjaminNolan commented 5 years ago

Version

3.11.0

Reproduction link

https://github.com/BenjaminNolan/vue-cli-public-container-url

Environment info

Environment Info:

  System:
    OS: Linux 4.15 Ubuntu 18.04.1 LTS (Bionic Beaver)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700T CPU @ 2.80GHz
  Binaries:
    Node: 10.16.3 - /usr/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 6.9.0 - /usr/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props: ^1.0.0 => 1.0.0 
    @vue/babel-plugin-transform-vue-jsx: ^1.0.0 => 1.0.0 
    @vue/babel-preset-app:  3.11.0 
    @vue/babel-preset-jsx:  1.1.0 
    @vue/babel-sugar-functional-vue:  1.0.0 
    @vue/babel-sugar-inject-h:  1.0.0 
    @vue/babel-sugar-v-model:  1.0.0 
    @vue/babel-sugar-v-on:  1.1.0 
    @vue/cli-overlay:  3.11.0 
    @vue/cli-plugin-babel: ^3.11.0 => 3.11.0 
    @vue/cli-plugin-eslint: ^3.11.0 => 3.11.0 
    @vue/cli-service: ^3.11.0 => 3.11.0 
    @vue/cli-shared-utils:  3.11.0 
    @vue/component-compiler-utils:  3.0.0 
    @vue/eslint-config-airbnb: ^4.0.1 => 4.0.1 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    babel-helper-vue-jsx-merge-props:  2.0.3 
    eslint-plugin-vue: ^5.2.3 => 5.2.3 (4.7.1)
    vue: ^2.5.17 => 2.6.10 
    vue-eslint-parser:  5.0.0 (2.0.3)
    vue-hot-reload-api:  2.3.4 
    vue-loader: ^15.7.1 => 15.7.1 
    vue-meta: ^1.4.3 => 1.5.0 
    vue-router: ^3.0.1 => 3.0.1 
    vue-style-loader: ^4.1.2 => 4.1.2 
    vue-svgicon: ^2.1.3 => 2.1.3 
    vue-template-compiler: ^2.6.10 => 2.6.10 
    vue-template-es2015-compiler:  1.9.1 
    vue2-animate: ^2.0.0 => 2.0.0 
    vuex: ^3.0.1 => 3.0.1 
    vuex-persistedstate: ^2.4.2 => 2.5.1 
    vuex-router-sync: ^5.0.0 => 5.0.0 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

Set devServer.public in vue.config.js:

module.exports = {
  devServer: {
    public: 'https://my.public.url',
  },
};

Run yarn serve from within a container.

What is expected?

 DONE  Compiled successfully in 2914ms                                                                                                                                                                   3:08:05 PM

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

  It seems you are running Vue CLI inside a container.
  Access the dev server via https://my.public.url/

What is actually happening?

 DONE  Compiled successfully in 2914ms                                                                                                                                                                   3:08:05 PM

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

  It seems you are running Vue CLI inside a container.
  Access the dev server via http://localhost:<your container's external mapped port>/

This is a minor one, really, but it got my goat enough to fix it. :) If you set devServer.public then serve already knows the public URL to display in order to access the dev server from within the container, and thus could display it rather than the localhost:mapped-port message it has currently.

A PR with a potential fix is impending from https://github.com/BenjaminNolan/vue-cli.

ThaDaVos commented 4 years ago

May it also be so that it's not actually running on the public set url?

I keep getting Invalid Host header even though my public url is set...