Skip to content

Commit 5542a91

Browse files
Merge branch 'master' into patch-2
2 parents 860b5e9 + 0b89fd9 commit 5542a91

File tree

13 files changed

+223
-35
lines changed

13 files changed

+223
-35
lines changed

bin/webpack-dev-server.js

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -239,30 +239,6 @@ function processOptions (config) {
239239
options.https = true;
240240
}
241241

242-
if (argv.cert) {
243-
options.cert = fs.readFileSync(
244-
path.resolve(argv.cert)
245-
);
246-
}
247-
248-
if (argv.key) {
249-
options.key = fs.readFileSync(
250-
path.resolve(argv.key)
251-
);
252-
}
253-
254-
if (argv.cacert) {
255-
options.ca = fs.readFileSync(
256-
path.resolve(argv.cacert)
257-
);
258-
}
259-
260-
if (argv.pfx) {
261-
options.pfx = fs.readFileSync(
262-
path.resolve(argv.pfx)
263-
);
264-
}
265-
266242
if (argv['pfx-passphrase']) {
267243
options.pfxPassphrase = argv['pfx-passphrase'];
268244
}

client-src/default/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/* global __resourceQuery WorkerGlobalScope self */
44
/* eslint prefer-destructuring: off */
5-
5+
const querystring = require('querystring');
66
const url = require('url');
77
const stripAnsi = require('strip-ansi');
88
const log = require('loglevel').getLogger('webpack-dev-server');
@@ -196,7 +196,10 @@ const socketUrl = url.format({
196196
auth: urlParts.auth,
197197
hostname,
198198
port: urlParts.port,
199-
pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : urlParts.path
199+
// If sockPath is provided it'll be passed in via the __resourceQuery as a
200+
// query param so it has to be parsed out of the querystring in order for the
201+
// client to open the socket to the correct location.
202+
pathname: urlParts.path == null || urlParts.path === '/' ? '/sockjs-node' : (querystring.parse(urlParts.path).sockPath || urlParts.path)
200203
});
201204

202205
socket(socketUrl, onSocketMsg);

lib/Server.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ function Server (compiler, options = {}, _log) {
103103

104104
this.watchOptions = options.watchOptions || {};
105105
this.contentBaseWatchers = [];
106+
// Replace leading and trailing slashes to normalize path
107+
this.sockPath = `/${options.sockPath ? options.sockPath.replace(/^\/|\/$/g, '') : 'sockjs-node'}`;
106108

107109
// Listening for events
108110
const invalidPlugin = () => {
@@ -553,6 +555,15 @@ function Server (compiler, options = {}, _log) {
553555
};
554556
}
555557

558+
for (const property of ['ca', 'pfx', 'key', 'cert']) {
559+
const value = options.https[property];
560+
const isBuffer = value instanceof Buffer;
561+
562+
if (value && !isBuffer && fs.lstatSync(value).isFile()) {
563+
options.https[property] = fs.readFileSync(path.resolve(value));
564+
}
565+
}
566+
556567
let fakeCert;
557568

558569
if (!options.https.key || !options.https.cert) {
@@ -800,7 +811,7 @@ Server.prototype.listen = function (port, hostname, fn) {
800811
});
801812

802813
socket.installHandlers(this.listeningApp, {
803-
prefix: '/sockjs-node'
814+
prefix: this.sockPath
804815
});
805816

806817
if (fn) {

lib/options.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
"socket": {
5252
"type": "string"
5353
},
54+
"sockPath": {
55+
"type": "string"
56+
},
5457
"watchOptions": {
5558
"type": "object"
5659
},
@@ -321,6 +324,7 @@
321324
"filename": "should be {String|RegExp|Function} (https://webpack.js.org/configuration/dev-server/#devserver-filename-)",
322325
"port": "should be {String|Number} (https://webpack.js.org/configuration/dev-server/#devserver-port)",
323326
"socket": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-socket)",
327+
"sockPath": "should be {String} (https://webpack.js.org/configuration/dev-server/#devserver-sockPath)",
324328
"watchOptions": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-watchoptions)",
325329
"writeToDisk": "should be {Boolean|Function} (https://github.com/webpack/webpack-dev-middleware#writetodisk)",
326330
"headers": "should be {Object} (https://webpack.js.org/configuration/dev-server/#devserver-headers-)",

lib/utils/addEntries.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function addEntries (config, options, server) {
2121
};
2222

2323
const domain = createDomain(options, app);
24-
const entries = [ `${require.resolve('../../client/')}?${domain}` ];
24+
const sockPath = options.sockPath ? `&sockPath=${options.sockPath}` : '';
25+
const entries = [ `${require.resolve('../../client/')}?${domain}${sockPath}` ];
2526

2627
if (options.hotOnly) {
2728
entries.push(require.resolve('webpack/hot/only-dev-server'));

package-lock.json

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/Https.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
'use strict';
22

33
const path = require('path');
4+
const fs = require('fs');
45
const request = require('supertest');
56
const helper = require('./helper');
67
const config = require('./fixtures/contentbase-config/webpack.config');
78
require('mocha-sinon');
89

10+
const httpsCertificateDirectory = path.join(__dirname, 'fixtures/https-certificate');
911
const contentBasePublic = path.join(__dirname, 'fixtures/contentbase-config/public');
1012

1113
describe('HTTPS', function testHttps() {
@@ -30,4 +32,46 @@ describe('HTTPS', function testHttps() {
3032
.expect(200, /Heyo/, done);
3133
});
3234
});
35+
36+
describe('ca, pfx, key and cert are buffer', () => {
37+
before((done) => {
38+
server = helper.start(config, {
39+
contentBase: contentBasePublic,
40+
https: {
41+
ca: fs.readFileSync(path.join(httpsCertificateDirectory, 'ca.pem')),
42+
pfx: fs.readFileSync(path.join(httpsCertificateDirectory, 'server.pfx')),
43+
key: fs.readFileSync(path.join(httpsCertificateDirectory, 'server.key')),
44+
cert: fs.readFileSync(path.join(httpsCertificateDirectory, 'server.crt')),
45+
passphrase: 'webpack-dev-server'
46+
}
47+
}, done);
48+
req = request(server.app);
49+
});
50+
51+
it('Request to index', (done) => {
52+
req.get('/')
53+
.expect(200, /Heyo/, done);
54+
});
55+
});
56+
57+
describe('ca, pfx, key and cert are string', () => {
58+
before((done) => {
59+
server = helper.start(config, {
60+
contentBase: contentBasePublic,
61+
https: {
62+
ca: path.join(httpsCertificateDirectory, 'ca.pem'),
63+
pfx: path.join(httpsCertificateDirectory, 'server.pfx'),
64+
key: path.join(httpsCertificateDirectory, 'server.key'),
65+
cert: path.join(httpsCertificateDirectory, 'server.crt'),
66+
passphrase: 'webpack-dev-server'
67+
}
68+
}, done);
69+
req = request(server.app);
70+
});
71+
72+
it('Request to index', (done) => {
73+
req.get('/')
74+
.expect(200, /Heyo/, done);
75+
});
76+
});
3377
});

test/Socket.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const request = require('supertest');
5+
const config = require('./fixtures/simple-config/webpack.config');
6+
const helper = require('./helper');
7+
8+
describe('socket options', () => {
9+
let server;
10+
let req;
11+
12+
afterEach((done) => {
13+
helper.close(done);
14+
req = null;
15+
server = null;
16+
});
17+
describe('default behavior', () => {
18+
beforeEach((done) => {
19+
server = helper.start(config, {}, done);
20+
req = request('http://localhost:8080');
21+
});
22+
23+
it('defaults to a path', () => {
24+
assert.ok(server.sockPath.match(/\/[a-z0-9\-/]+[^/]$/));
25+
});
26+
27+
it('responds with a 200', (done) => {
28+
req.get('/sockjs-node').expect(200, done);
29+
});
30+
});
31+
32+
describe('socksPath option', () => {
33+
const path = '/foo/test/bar';
34+
beforeEach((done) => {
35+
server = helper.start(config, {
36+
sockPath: '/foo/test/bar/'
37+
}, done);
38+
req = request('http://localhost:8080');
39+
});
40+
41+
it('sets the sock path correctly and strips leading and trailing /s', () => {
42+
assert.equal(server.sockPath, path);
43+
});
44+
45+
it('responds with a 200 second', (done) => {
46+
req.get(path).expect(200, done);
47+
});
48+
});
49+
});

test/cli.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ const path = require('path');
88
const execa = require('execa');
99
const runDevServer = require('./helpers/run-webpack-dev-server');
1010

11+
const httpsCertificateDirectory = path.join(__dirname, 'fixtures/https-certificate');
12+
const caPath = path.join(httpsCertificateDirectory, 'ca.pem');
13+
const pfxPath = path.join(httpsCertificateDirectory, 'server.pfx');
14+
const keyPath = path.join(httpsCertificateDirectory, 'server.key');
15+
const certPath = path.join(httpsCertificateDirectory, 'server.crt');
16+
1117
describe('CLI', () => {
1218
it('process.env.WEBPACK_DEV_SERVER', (done) => {
1319
runDevServer()
@@ -28,6 +34,26 @@ describe('CLI', () => {
2834
.catch(done);
2935
}).timeout(18000);
3036

37+
it('--https', (done) => {
38+
runDevServer('--https')
39+
.then((output) => {
40+
assert(output.code === 0);
41+
assert(output.stdout.indexOf('Project is running at') >= 0);
42+
done();
43+
})
44+
.catch(done);
45+
}).timeout(18000);
46+
47+
it('--https --cacert --pfx --key --cert --pfx-passphrase', (done) => {
48+
runDevServer(`--https --cacert ${caPath} --pfx ${pfxPath} --key ${keyPath} --cert ${certPath} --pfx-passphrase webpack-dev-server`)
49+
.then((output) => {
50+
assert(output.code === 0);
51+
assert(output.stdout.indexOf('Project is running at') >= 0);
52+
done();
53+
})
54+
.catch(done);
55+
}).timeout(18000);
56+
3157
it('should exit the process when SIGINT is detected', (done) => {
3258
const cliPath = path.resolve(__dirname, '../bin/webpack-dev-server.js');
3359
const examplePath = path.resolve(__dirname, '../examples/cli/public');
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpQIBAAKCAQEAxAUVLFM+K3XDLQkBi7xt0s1Ip7JoHYDskzUDQNHjjMkUq5kv
3+
C/hf5Ei1J6qruJs3Xqg86Nl4+ed4ynUajAkRRibhp0P1SG1tgPssIK6iC7g8heYu
4+
Dy9WkFuMie0513zjSn6bMEAK5TegxYAWCbaCZX/Fw9bDniabL/zuOv4sf8J4EPhs
5+
EENnH6sUE9HxPUgQmNt1Tbd0j1Cd5PXrSTLyfVPRh0m9QhXTUHuxsse8XSn9U2sw
6+
duxJTWRINmhffYn+O7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Yqg++qGbLtZjQoPRFt85N6ZxMsqA5b0iK3mXq1auJDdx1rAlT9z6q
23+
9JM/YNAkbZsvEVq9vIYxw31w98T1GYhpzBM+yDhzir+9tv5YhQKa1dXDWi1JhWwz
24+
YN45pWkCgYEAxuVsJ4D4Th5o050ppWpnxM/WuMhIUKqaoFTVucMKFzn+g24y9pv5
25+
miYdNYIk4Y+4pzHG6ZGZSHJcQ9BLui6H/nLQnqkgCb2lT5nfp7/GKdus7BdcjPGs
26+
fcV46yL7/X0m8nDb3hkwwrDTU4mKFkMrzKpjdZBsttEmW0Aw/3y36gU=
27+
-----END RSA PRIVATE KEY-----
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDXTCCAkWgAwIBAgIJALz8gD/gAt0OMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
3+
BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX
4+
aWRnaXRzIFB0eSBMdGQwHhcNMTgxMDIzMTgyMTQ5WhcNMTkxMDIzMTgyMTQ5WjBF
5+
MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50
6+
ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
7+
CgKCAQEAxAUVLFM+K3XDLQkBi7xt0s1Ip7JoHYDskzUDQNHjjMkUq5kvC/hf5Ei1
8+
J6qruJs3Xqg86Nl4+ed4ynUajAkRRibhp0P1SG1tgPssIK6iC7g8heYuDy9WkFuM
9+
ie0513zjSn6bMEAK5TegxYAWCbaCZX/Fw9bDniabL/zuOv4sf8J4EPhsEENnH6sU
10+
E9HxPUgQmNt1Tbd0j1Cd5PXrSTLyfVPRh0m9QhXTUHuxsse8XSn9U2swduxJTWRI
11+
NmhffYn+O7kbJGI77xYr8u58Rsf3HCMI8DTKZNvQLChvvtLJ9ckyu7Q+T8emgklS
12+
tASm3V2UtnriaK/IQEhgSdxqVRib3QIDAQABo1AwTjAdBgNVHQ4EFgQUDZBhVKdb
13+
3BRhLIhuuE522Vsul0IwHwYDVR0jBBgwFoAUDZBhVKdb3BRhLIhuuE522Vsul0Iw
14+
DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEABh9WWZwWLgb9/DcTxL72
15+
6pI96t4jiF79Q+pPefkaIIi0mE6yodWrTAsBQu9I6bNRaEcCSoiXkP2bqskD/UGg
16+
LwUFgSrDOAA3UjdHw3QU5g2NocduG7mcFwA40TB98sOsxsUyYlzSyWzoiQWwPYwb
17+
hek1djuWkqPXsTjlj54PTPN/SjTFmo4p5Ip6nbRf2nOREl7v0rJpGbJvXiCMYyd+
18+
Zv+j4mRjCGo8ysMR2HjCUGkYReLAgKyyz3M7i8vevJhKslyOmy6Txn4F0nPVumaU
19+
DDIy4xXPW1STWfsmSYJfYW3wa0wk+pJQ3j2cTzkPQQ8gwpvM3U9DJl43uwb37v6I
20+
7Q==
21+
-----END CERTIFICATE-----
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDEBRUsUz4rdcMt
3+
CQGLvG3SzUinsmgdgOyTNQNA0eOMyRSrmS8L+F/kSLUnqqu4mzdeqDzo2Xj553jK
4+
dRqMCRFGJuGnQ/VIbW2A+ywgrqILuDyF5i4PL1aQW4yJ7TnXfONKfpswQArlN6DF
5+
gBYJtoJlf8XD1sOeJpsv/O46/ix/wngQ+GwQQ2cfqxQT0fE9SBCY23VNt3SPUJ3k
6+
9etJMvJ9U9GHSb1CFdNQe7Gyx7xdKf1TazB27ElNZEg2aF99if47uRskYjvvFivy
7+
7nxGx/ccIwjwNMpk29AsKG++0sn1yTK7tD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kN3HWsCVP3Pqr0kz9g0CRtmy8RWr28hjHDfXD3xPUZ
24+
iGnMEz7IOHOKv722/liFAprV1cNaLUmFbDNg3jmlaQKBgQDG5WwngPhOHmjTnSml
25+
amfEz9a4yEhQqpqgVNW5wwoXOf6DbjL2m/maJh01giThj7inMcbpkZlIclxD0Eu6
26+
Lof+ctCeqSAJvaVPmd+nv8Yp26zsF1yM8ax9xXjrIvv9fSbycNveGTDCsNNTiYoW
27+
QyvMqmN1kGy20SZbQDD/fLfqBQ==
28+
-----END PRIVATE KEY-----
2.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)