Skip to content

fix(cli-service): do not log absolute baseUrl in terminal, close #2877 #2900

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

Merged
merged 1 commit into from
Nov 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports = (api, options) => {
const prepareProxy = require('../util/prepareProxy')
const launchEditorMiddleware = require('launch-editor-middleware')
const validateWebpackConfig = require('../util/validateWebpackConfig')
const isAbsoluteUrl = require('../util/isAbsoluteUrl')

// resolve webpack config
const webpackConfig = api.resolveWebpackConfig()
Expand Down Expand Up @@ -89,7 +90,7 @@ module.exports = (api, options) => {
protocol,
host,
port,
options.baseUrl
isAbsoluteUrl(options.baseUrl) ? '/' : options.baseUrl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't that break for baseUrl: http://localhost:8081/someBasePath/ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set baseUrl to http://localhost:8081/someBasePath/ doesn't mean to start the dev-server on localhost:8081, the dev-server would still be started on ${host}:${port}.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but doesn't the console now say " go to host: port/" even though people would have to go to "localhost:port/baseurl"?

I'm honestly confused because paths and hosts in webpack can be confusing as hell to me

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider those two cases here:

  1. Asset files (js/css/img) are served by webpack-dev-server (eg. localhost:8080), and user uses a reverse proxy to access the html (eg. localhost:3000/app/). In this case, baseUrl should be set to http://localhost:8080/, but user need to open http://localhost:3000/app/ in browser.

  2. Asset files (js/css/img) are served by webpack-dev-server (eg. localhost:8080), and user uses a reverse proxy to access the asset files (eg. localhost:3000/assets/). In this case, baseUrl should be set to http://localhost:3000/assets/, and user need to go to http://localhsot:8080 in browser.

What I want to say is, we cannot infer which url should user open in browser if user set baseUrl to a absolute url. What we can do is tell user "we have started your dev-server on localhost:8080"...

And, yes it is confusing. 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, that was very helpful. Thanks.

)

const proxySettings = prepareProxy(
Expand Down
4 changes: 4 additions & 0 deletions packages/@vue/cli-service/lib/util/isAbsoluteUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function isAbsoluteUrl (url) {
// A URL is considered absolute if it begins with "<scheme>://" or "//"
return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url)
}