Skip to content

Commit 3a0e7ac

Browse files
committed
respect custom devServer https, host & port;
- look for values in `pwa.config.js` if CLI value is default - priority: ENV > (flag == default ? config : default) - closes #26
1 parent 6ded951 commit 3a0e7ac

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/cli/lib/watch.js

+17-11
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,37 @@ module.exports = function (src, opts) {
1717
let publicPath = c.options.output.publicPath;
1818

1919
let protocol = 'http';
20-
let port = PORT || opts.port || 8080;
21-
let hostname = HOST || opts.host || 'localhost';
22-
23-
if (opts.https || HTTPS) {
24-
let { key, cert, cacert } = opts;
20+
let port = PORT || opts.port;
21+
let hostname = HOST || opts.host;
22+
let dev = c.options.devServer;
23+
24+
// use custom configs if KEY === default
25+
port = port === 8080 && dev.port || port;
26+
hostname = hostname === 'localhost' && dev.host || hostname;
27+
28+
if (opts.https || HTTPS || dev.https) {
29+
let tmp = Object.assign({}, dev.https, opts);
30+
let { key, cert, cacert } = tmp;
31+
let hasCA = Boolean(cacert);
2532
protocol = 'https';
2633

2734
if (key && cert) {
2835
key = resolve(cwd, key);
2936
cert = resolve(cwd, cert);
3037
cacert = cacert && resolve(cwd, cacert);
3138
if (existsSync(key) && existsSync(cert)) {
32-
opts.https = { key, cert, ca:cacert };
39+
dev.https = { key, cert, ca:cacert };
3340
} else {
3441
let gutter = ' '.repeat(4);
35-
let space = opts.cacert ? ' '.repeat(2) : '';
42+
let space = hasCA ? ' '.repeat(2) : '';
3643
let out = 'Certificate component(s) not found at locations provided!\n';
3744
out += colors.bold.white('--key ') + space + gutter + colors.italic.dim(key) + '\n';
3845
out += colors.bold.white('--cert') + space + gutter + colors.italic.dim(cert);
39-
if (opts.cacert) out += '\n' + colors.bold.white('--cacert') + gutter + colors.italic.dim(cacert);
46+
if (hasCA) out += '\n' + colors.bold.white('--cacert') + gutter + colors.italic.dim(cacert);
4047
return log.error(out);
4148
}
4249
} else {
43-
opts.https = true;
50+
dev.https = true;
4451
log.warn('Relying on self-signed certificate from `webpack-dev-server` internals');
4552
}
4653
}
@@ -83,11 +90,10 @@ module.exports = function (src, opts) {
8390
});
8491
}
8592

86-
let server = new Server(c, Object.assign(c.options.devServer, {
93+
let server = new Server(c, Object.assign(dev, {
8794
publicPath,
8895
inline: true,
8996
contentBase: src,
90-
https: opts.https,
9197
host: hostname,
9298
// @see webpack-dev-server/pull/1486
9399
// noInfo: true,

0 commit comments

Comments
 (0)