|
| 1 | +# HTTPS server |
| 2 | + |
| 3 | +You may choose to run `webpack-dev-server` on `https`. |
| 4 | + |
| 5 | +Customize `server.options` configuration with the following options: |
| 6 | + |
| 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. |
| 14 | + |
| 15 | +```js |
| 16 | +module.exports = { |
| 17 | + // ... |
| 18 | + devServer: { |
| 19 | + server: { |
| 20 | + type: "https", |
| 21 | + options: { |
| 22 | + key: "./ssl/server.key", |
| 23 | + pfx: "./ssl/server.pfx", |
| 24 | + cert: "./ssl/server.crt", |
| 25 | + ca: "./ssl/ca.pem", |
| 26 | + passphrase: "webpack-dev-server", |
| 27 | + }, |
| 28 | + }, |
| 29 | + }, |
| 30 | +}; |
| 31 | +``` |
| 32 | + |
| 33 | +Usage via CLI: |
| 34 | + |
| 35 | +```console |
| 36 | +npx webpack serve --open --server-type https --server-options-key ./ssl/server.key --server-options-cert ./ssl/server.crt --server-options-ca ./ssl/ca.pem --server-options-passphrase webpack-dev-server |
| 37 | +``` |
| 38 | + |
| 39 | +You can also directly pass the contents of respective files: |
| 40 | + |
| 41 | +```js |
| 42 | +const fs = require("fs"); |
| 43 | +const path = require("path"); |
| 44 | + |
| 45 | +module.exports = { |
| 46 | + // ... |
| 47 | + devServer: { |
| 48 | + server: { |
| 49 | + type: "https", |
| 50 | + options: { |
| 51 | + key: fs.readFileSync(path.join(__dirname, "./ssl/server.key")), |
| 52 | + pfx: fs.readFileSync(path.join(__dirname, "./ssl/server.pfx")), |
| 53 | + cert: fs.readFileSync(path.join(__dirname, "./ssl/server.crt")), |
| 54 | + ca: fs.readFileSync(path.join(__dirname, "./ssl/ca.pem")), |
| 55 | + passphrase: "webpack-dev-server", |
| 56 | + requestCert: true, |
| 57 | + }, |
| 58 | + }, |
| 59 | + }, |
| 60 | +}; |
| 61 | +``` |
| 62 | + |
| 63 | +## What Should Happen |
| 64 | + |
| 65 | +1. The script should open `https://localhost:8080/` in your default browser. |
| 66 | +2. You should see the text on the page itself change to read `Success!`. |
0 commit comments