Skip to content
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
30 changes: 15 additions & 15 deletions lib/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,21 @@ class Server {
});
}

showStatus() {
const suffix =
this.options.inline !== false || this.options.lazy === true
? '/'
: '/webpack-dev-server/';
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;

status(
uri,
this.options,
this.log,
this.options.stats && this.options.stats.colors
);
}

listen(port, hostname, fn) {
this.hostname = hostname;

Expand Down Expand Up @@ -878,21 +893,6 @@ class Server {
return false;
}

showStatus() {
const suffix =
this.options.inline !== false || this.options.lazy === true
? '/'
: '/webpack-dev-server/';
const uri = `${createDomain(this.options, this.listeningApp)}${suffix}`;

status(
uri,
this.options,
this.log,
this.options.stats && this.options.stats.colors
);
}

// eslint-disable-next-line
sockWrite(sockets, type, data) {
sockets.forEach((socket) => {
Expand Down
21 changes: 21 additions & 0 deletions lib/utils/runOpen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const open = require('opn');

function runOpen(uri, options, log) {
let openOptions = {};
let openMessage = 'Unable to open browser';

if (typeof options.open === 'string') {
openOptions = { app: options.open };
openMessage += `: ${options.open}`;
}

open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
log.warn(
`${openMessage}. If you are running in a headless environment, please do not use the --open flag`
);
});
}

module.exports = runOpen;
16 changes: 2 additions & 14 deletions lib/utils/status.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const open = require('opn');
const colors = require('./colors');
const runOpen = require('./runOpen');

// TODO: don't emit logs when webpack-dev-server is used via Node.js API
function status(uri, options, log, useColor) {
Expand Down Expand Up @@ -44,19 +44,7 @@ function status(uri, options, log, useColor) {
}

if (options.open) {
let openOptions = {};
let openMessage = 'Unable to open browser';

if (typeof options.open === 'string') {
openOptions = { app: options.open };
openMessage += `: ${options.open}`;
}

open(`${uri}${options.openPage || ''}`, openOptions).catch(() => {
log.warn(
`${openMessage}. If you are running in a headless environment, please do not use the --open flag`
);
});
runOpen(uri, options, log);
}
}

Expand Down