Skip to content

Commit 2b1208d

Browse files
authored
docs: improve https example (#3828)
1 parent 9bd6bc8 commit 2b1208d

File tree

10 files changed

+78
-25
lines changed

10 files changed

+78
-25
lines changed

examples/https/boolean/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https
2+
3+
You may choose to wish to run `webpack-dev-server` on `https`.
4+
5+
## boolean
6+
7+
Use HTTPS protocol.
8+
9+
```js
10+
module.exports = {
11+
// ...
12+
devServer: {
13+
https: true,
14+
},
15+
};
16+
```
17+
18+
Usage via CLI:
19+
20+
```console
21+
npx webpack serve --open --https
22+
```
23+
24+
## What Should Happen
25+
26+
1. The script should open `https://localhost:8080/` in your default browser.
27+
2. You should see the text on the page itself change to read `Success!`.
File renamed without changes.

examples/https/webpack.config.js renamed to examples/https/boolean/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// our setup function adds behind-the-scenes bits to the config that all of our
44
// examples need
5-
const { setup } = require("../util");
5+
const { setup } = require("../../util");
66

77
module.exports = setup({
88
context: __dirname,

examples/https/README.md renamed to examples/https/object/README.md

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

33
You may choose to wish to run `webpack-dev-server` on `https`.
44

5-
## https
5+
Customize `https` configuration with the following options:
66

7-
Use HTTPS protocol.
7+
- `key`: Path to an SSL key.
8+
- `pfx`: Path to an SSL pfx file.
9+
- `cert`: Path to an SSL certificate or content of an SSL certificate.
10+
- `ca`: Path to an SSL CA certificate or content of an SSL CA certificate.
11+
- `crl`: Path to PEM formatted CRLs (Certificate Revocation Lists) or content of PEM formatted CRLs (Certificate Revocation Lists).
12+
- `passphrase`: Passphrase for a pfx file.
13+
- `requestCert`: Request for an SSL certificate.
814

915
```js
1016
module.exports = {
1117
// ...
1218
devServer: {
13-
https: true,
19+
https: {
20+
key: "../ssl/server.key",
21+
pfx: "../ssl/server.pfx",
22+
cert: "../ssl/server.crt",
23+
ca: "../ssl/ca.pem",
24+
passphrase: "webpack-dev-server",
25+
},
1426
},
1527
};
1628
```
1729

1830
Usage via CLI:
1931

2032
```console
21-
npx webpack serve --open --https
33+
npx webpack serve --open --https-key ./ssl/server.key --https-pfx ./ssl/server.pfx --https-cert ./ssl/server.crt --https-ca ./ssl/ca.pem --https-passphrase webpack-dev-server --https-request-cert
2234
```
2335

24-
## https options
25-
26-
Customize `https` configuration with the following options:
27-
28-
- `key`: Path to an SSL key.
29-
- `pfx`: Path to an SSL pfx file.
30-
- `cert`: Path to an SSL certificate.
31-
- `ca`: Path to an SSL CA certificate.
32-
- `passphrase`: Passphrase for a pfx file.
33-
- `requestCert`: Request for an SSL certificate.
36+
You can also directly pass the contents of respective files:
3437

3538
```js
39+
const fs = require("fs");
40+
const path = require("path");
41+
3642
module.exports = {
3743
// ...
3844
devServer: {
3945
https: {
40-
key: "./ssl/server.key",
41-
pfx: "./ssl/server.pfx",
42-
cert: "./ssl/server.crt",
43-
ca: "./ssl/ca.pem",
46+
key: fs.readFileSync(path.join(__dirname, "./ssl/server.key")),
47+
pfx: fs.readFileSync(path.join(__dirname, "./ssl/server.pfx")),
48+
cert: fs.readFileSync(path.join(__dirname, "./ssl/server.crt")),
49+
ca: fs.readFileSync(path.join(__dirname, "./ssl/ca.pem")),
4450
passphrase: "webpack-dev-server",
4551
requestCert: true,
4652
},
4753
},
4854
};
4955
```
5056

51-
Usage via CLI:
52-
53-
```console
54-
npx webpack serve --open --https-key ./ssl/server.key --https-pfx ./ssl/server.pfx --https-cert ./ssl/server.crt --https-ca ./ssl/ca.pem --https-passphrase webpack-dev-server --https-request-cert
55-
```
56-
5757
## What Should Happen
5858

5959
1. The script should open `https://localhost:8080/` in your default browser.

examples/https/object/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
const target = document.querySelector("#target");
4+
5+
target.classList.add("pass");
6+
target.innerHTML = "Success!";
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use strict";
2+
3+
// our setup function adds behind-the-scenes bits to the config that all of our
4+
// examples need
5+
const { setup } = require("../../util");
6+
7+
module.exports = setup({
8+
context: __dirname,
9+
entry: "./app.js",
10+
devServer: {
11+
https: {
12+
key: "./ssl/server.key",
13+
pfx: "./ssl/server.pfx",
14+
cert: "./ssl/server.crt",
15+
ca: "./ssl/ca.pem",
16+
passphrase: "webpack-dev-server",
17+
requestCert: true,
18+
},
19+
},
20+
});

0 commit comments

Comments
 (0)