Skip to content

Commit f4f4b45

Browse files
authored
feat: add more https option related cli flags (#3241)
1 parent 9f52d3f commit f4f4b45

File tree

5 files changed

+212
-0
lines changed

5 files changed

+212
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,13 @@ Options:
9797
--no-live-reload Disables live reloading on changing files.
9898
--https Use HTTPS protocol.
9999
--no-https Do not use HTTPS protocol.
100+
--https-passphrase <value> Passphrase for a pfx file.
101+
--https-key <value> Path to an SSL key.
102+
--https-pfx <value> Path to an SSL pfx file.
103+
--https-cert <value> Path to an SSL certificate.
104+
--https-cacert <value> Path to an SSL CA certificate.
105+
--https-request-cert Request for an SSL certificate.
106+
--no-https-request-cert Do not request for an SSL certificate.
100107
--http2 Use HTTP/2, must be used with HTTPS.
101108
--no-http2 Do not use HTTP/2.
102109
--bonjour Broadcasts the server via ZeroConf networking on start.

bin/cli-flags.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,97 @@ module.exports = {
128128
negatedDescription: 'Do not use HTTPS protocol.',
129129
negative: true,
130130
},
131+
{
132+
name: 'https-passphrase',
133+
type: String,
134+
configs: [
135+
{
136+
type: 'string',
137+
},
138+
],
139+
description: 'Passphrase for a pfx file.',
140+
processor(opts) {
141+
opts.https = opts.https || {};
142+
opts.https.passphrase = opts.httpsPassphrase;
143+
delete opts.httpsPassphrase;
144+
},
145+
},
146+
{
147+
name: 'https-key',
148+
type: String,
149+
configs: [
150+
{
151+
type: 'string',
152+
},
153+
],
154+
description: 'Path to an SSL key.',
155+
processor(opts) {
156+
opts.https = opts.https || {};
157+
opts.https.key = opts.httpsKey;
158+
delete opts.httpsKey;
159+
},
160+
},
161+
{
162+
name: 'https-pfx',
163+
type: String,
164+
configs: [
165+
{
166+
type: 'string',
167+
},
168+
],
169+
description: 'Path to an SSL pfx file.',
170+
processor(opts) {
171+
opts.https = opts.https || {};
172+
opts.https.pfx = opts.httpsPfx;
173+
delete opts.httpsPfx;
174+
},
175+
},
176+
{
177+
name: 'https-cert',
178+
type: String,
179+
configs: [
180+
{
181+
type: 'string',
182+
},
183+
],
184+
description: 'Path to an SSL certificate.',
185+
processor(opts) {
186+
opts.https = opts.https || {};
187+
opts.https.cert = opts.httpsCert;
188+
delete opts.httpsCert;
189+
},
190+
},
191+
{
192+
name: 'https-cacert',
193+
type: String,
194+
configs: [
195+
{
196+
type: 'string',
197+
},
198+
],
199+
description: 'Path to an SSL CA certificate.',
200+
processor(opts) {
201+
opts.https = opts.https || {};
202+
opts.https.cacert = opts.httpsCacert;
203+
delete opts.httpsCacert;
204+
},
205+
},
206+
{
207+
name: 'https-request-cert',
208+
type: Boolean,
209+
configs: [
210+
{
211+
type: 'boolean',
212+
},
213+
],
214+
description: 'Request for an SSL certificate.',
215+
negatedDescription: 'Do not request for an SSL certificate.',
216+
processor(opts) {
217+
opts.https = opts.https || {};
218+
opts.https.requestCert = opts.httpsRequestCert;
219+
delete opts.httpsRequestCert;
220+
},
221+
},
131222
{
132223
name: 'http2',
133224
type: Boolean,

test/cli/__snapshots__/cli.test.js.snap.webpack4

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ exports[`CLI --https 1`] = `
116116
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
117117
`;
118118

119+
exports[`CLI --https-request-cert 1`] = `
120+
"<i> [webpack-dev-server] Project is running at:
121+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
122+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
123+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
124+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
125+
`;
126+
119127
exports[`CLI --no-bonjour 1`] = `
120128
"<i> [webpack-dev-server] Project is running at:
121129
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
@@ -148,6 +156,22 @@ exports[`CLI --no-https 1`] = `
148156
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
149157
`;
150158

159+
exports[`CLI --no-https-request-cert 1`] = `
160+
"<i> [webpack-dev-server] Project is running at:
161+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
162+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
163+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
164+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
165+
`;
166+
167+
exports[`CLI https options 1`] = `
168+
"<i> [webpack-dev-server] Project is running at:
169+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
170+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
171+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
172+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
173+
`;
174+
151175
exports[`CLI should generate correct cli flags 1`] = `
152176
"Usage: webpack serve|s [entries...] [options]
153177

@@ -199,6 +223,13 @@ Options:
199223
--no-live-reload Disables live reloading on changing files.
200224
--https Use HTTPS protocol.
201225
--no-https Do not use HTTPS protocol.
226+
--https-passphrase <value> Passphrase for a pfx file.
227+
--https-key <value> Path to an SSL key.
228+
--https-pfx <value> Path to an SSL pfx file.
229+
--https-cert <value> Path to an SSL certificate.
230+
--https-cacert <value> Path to an SSL CA certificate.
231+
--https-request-cert Request for an SSL certificate.
232+
--no-https-request-cert Do not request for an SSL certificate.
202233
--http2 Use HTTP/2, must be used with HTTPS.
203234
--no-http2 Do not use HTTP/2.
204235
--bonjour Broadcasts the server via ZeroConf

test/cli/__snapshots__/cli.test.js.snap.webpack5

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ exports[`CLI --https 1`] = `
116116
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
117117
`;
118118

119+
exports[`CLI --https-request-cert 1`] = `
120+
"<i> [webpack-dev-server] Project is running at:
121+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
122+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
123+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
124+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
125+
`;
126+
119127
exports[`CLI --no-bonjour 1`] = `
120128
"<i> [webpack-dev-server] Project is running at:
121129
<i> [webpack-dev-server] Loopback: http://localhost:<port>/
@@ -148,6 +156,22 @@ exports[`CLI --no-https 1`] = `
148156
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
149157
`;
150158

159+
exports[`CLI --no-https-request-cert 1`] = `
160+
"<i> [webpack-dev-server] Project is running at:
161+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
162+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
163+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
164+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
165+
`;
166+
167+
exports[`CLI https options 1`] = `
168+
"<i> [webpack-dev-server] Project is running at:
169+
<i> [webpack-dev-server] Loopback: https://localhost:<port>/
170+
<i> [webpack-dev-server] On Your Network (IPv4): https://<network-ip-v4>:<port>/
171+
<i> [webpack-dev-server] On Your Network (IPv6): https://[<network-ip-v6>]:<port>/
172+
<i> [webpack-dev-server] Content not from webpack is served from '<cwd>/public' directory"
173+
`;
174+
151175
exports[`CLI should generate correct cli flags 1`] = `
152176
"Usage: webpack serve|s [entries...] [options]
153177

@@ -201,6 +225,13 @@ Options:
201225
--no-live-reload Disables live reloading on changing files.
202226
--https Use HTTPS protocol.
203227
--no-https Do not use HTTPS protocol.
228+
--https-passphrase <value> Passphrase for a pfx file.
229+
--https-key <value> Path to an SSL key.
230+
--https-pfx <value> Path to an SSL pfx file.
231+
--https-cert <value> Path to an SSL certificate.
232+
--https-cacert <value> Path to an SSL CA certificate.
233+
--https-request-cert Request for an SSL certificate.
234+
--no-https-request-cert Do not request for an SSL certificate.
204235
--http2 Use HTTP/2, must be used with HTTPS.
205236
--no-http2 Do not use HTTP/2.
206237
--bonjour Broadcasts the server via ZeroConf

test/cli/cli.test.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const { testBin, normalizeStderr } = require('../helpers/test-bin');
99
const localIPv4 = internalIp.v4.sync();
1010
const localIPv6 = internalIp.v6.sync();
1111

12+
const httpsCertificateDirectory = path.resolve(
13+
__dirname,
14+
'../fixtures/https-certificate'
15+
);
16+
1217
describe('CLI', () => {
1318
it('--hot', (done) => {
1419
testBin('--hot --stats=detailed')
@@ -139,6 +144,53 @@ describe('CLI', () => {
139144
.catch(done);
140145
});
141146

147+
it('https options', (done) => {
148+
const pfxFile = path.join(httpsCertificateDirectory, 'server.pfx');
149+
const key = path.join(httpsCertificateDirectory, 'server.key');
150+
const cert = path.join(httpsCertificateDirectory, 'server.crt');
151+
const cacert = path.join(httpsCertificateDirectory, 'ca.pem');
152+
const passphrase = 'webpack-dev-server';
153+
154+
testBin(
155+
`--https-key ${key} --https-pfx ${pfxFile} --https-passphrase ${passphrase} --https-cert ${cert} --https-cacert ${cacert}`
156+
)
157+
.then((output) => {
158+
expect(output.exitCode).toEqual(0);
159+
expect(
160+
normalizeStderr(output.stderr, { ipv6: true, https: true })
161+
).toMatchSnapshot();
162+
163+
done();
164+
})
165+
.catch(done);
166+
});
167+
168+
it('--https-request-cert', (done) => {
169+
testBin('--https-request-cert')
170+
.then((output) => {
171+
expect(output.exitCode).toEqual(0);
172+
expect(
173+
normalizeStderr(output.stderr, { ipv6: true, https: true })
174+
).toMatchSnapshot();
175+
176+
done();
177+
})
178+
.catch(done);
179+
});
180+
181+
it('--no-https-request-cert', (done) => {
182+
testBin('--no-https-request-cert')
183+
.then((output) => {
184+
expect(output.exitCode).toEqual(0);
185+
expect(
186+
normalizeStderr(output.stderr, { ipv6: true, https: true })
187+
).toMatchSnapshot();
188+
189+
done();
190+
})
191+
.catch(done);
192+
});
193+
142194
it('--no-https', (done) => {
143195
testBin('--no-https')
144196
.then((output) => {

0 commit comments

Comments
 (0)