diff --git a/packages/neutrino-middleware-dev-server/index.js b/packages/neutrino-middleware-dev-server/index.js index c26832b..89dad19 100644 --- a/packages/neutrino-middleware-dev-server/index.js +++ b/packages/neutrino-middleware-dev-server/index.js @@ -21,10 +21,22 @@ module.exports = (neutrino, options = {}) => { const config = neutrino.config; const server = ramda.pathOr({}, ['options', 'server'], neutrino); const protocol = process.env.HTTPS ? 'https' : 'http'; - const host = process.env.HOST || server.host || options.host || '0.0.0.0'; + const publicHost = process.env.HOST; const port = process.env.PORT || server.port || options.port || 5000; const https = (protocol === 'https') || server.https || options.https; let openInBrowser = false; + let serverPublic = false; + let host = 'localhost'; + + if (server.public !== undefined) { + serverPublic = Boolean(server.public); + } else if (options.public !== undefined) { + serverPublic = Boolean(options.public); + } + + if (serverPublic) { + host = '0.0.0.0'; + } if (server.open !== undefined) { openInBrowser = Boolean(server.open); @@ -39,7 +51,8 @@ module.exports = (neutrino, options = {}) => { .contentBase(neutrino.options.source) .historyApiFallback(true) .hot(true) - .headers({ host }) + .headers({ host: publicHost }) + .public(publicHost) .publicPath('/') .stats({ assets: false, diff --git a/packages/neutrino-preset-web/index.js b/packages/neutrino-preset-web/index.js index f835725..908ce52 100644 --- a/packages/neutrino-preset-web/index.js +++ b/packages/neutrino-preset-web/index.js @@ -114,7 +114,7 @@ module.exports = (neutrino) => { })) .when(process.env.NODE_ENV === 'development', (config) => { neutrino.use(hot); - neutrino.use(devServer, { host: 'localhost' }); + neutrino.use(devServer); config.devtool('source-map'); }, (config) => { neutrino.use(clean, { paths: [neutrino.options.output] }); diff --git a/packages/neutrino/bin/start.js b/packages/neutrino/bin/start.js index c3a8b9a..3ca7fd3 100644 --- a/packages/neutrino/bin/start.js +++ b/packages/neutrino/bin/start.js @@ -14,6 +14,8 @@ const whenIPReady = new Promise((done, failed) => { }); }); +whenIPReady.then(ip => process.env.HOST = process.env.HOST || ip); + module.exports = (middleware, options) => { const spinner = ora('Building project').start();