Skip to content

fix(cli-service): make sockjs url fixed with hostname #1476

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
Jun 5, 2018
Merged
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
47 changes: 28 additions & 19 deletions packages/@vue/cli-service/lib/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = (api, options) => {
const isProduction = process.env.NODE_ENV === 'production'

const path = require('path')
const url = require('url')
const chalk = require('chalk')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
Expand Down Expand Up @@ -60,11 +61,37 @@ module.exports = (api, options) => {
}
}

// resolve server options
const useHttps = args.https || projectDevServerOptions.https || defaults.https
const protocol = useHttps ? 'https' : 'http'
const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
const port = await portfinder.getPortPromise()

const urls = prepareURLs(
protocol,
host,
port,
options.baseUrl
)

const proxySettings = prepareProxy(
projectDevServerOptions.proxy,
api.resolve('public')
)

// inject dev & hot-reload middleware entries
if (!isProduction) {
const sockjsUrl = url.format({
protocol,
port,
hostname: urls.lanUrlForConfig || 'localhost',
pathname: '/sockjs-node'
})

const devClients = [
// dev server client
require.resolve(`webpack-dev-server/client`) + (options.baseUrl !== '/' ? '?/sockjs-node' : ''),
require.resolve(`webpack-dev-server/client`) + `?${sockjsUrl}`,
// hmr client
require.resolve(projectDevServerOptions.hotOnly
? 'webpack/hot/only-dev-server'
Expand All @@ -82,24 +109,6 @@ module.exports = (api, options) => {
// create compiler
const compiler = webpack(webpackConfig)

// resolve server options
const useHttps = args.https || projectDevServerOptions.https || defaults.https
const host = args.host || process.env.HOST || projectDevServerOptions.host || defaults.host
portfinder.basePort = args.port || process.env.PORT || projectDevServerOptions.port || defaults.port
const port = await portfinder.getPortPromise()

const urls = prepareURLs(
useHttps ? 'https' : 'http',
host,
port,
options.baseUrl
)

const proxySettings = prepareProxy(
projectDevServerOptions.proxy,
api.resolve('public')
)

// create server
const server = new WebpackDevServer(compiler, Object.assign({
clientLogLevel: 'none',
Expand Down