-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhmr.js
More file actions
66 lines (55 loc) · 1.71 KB
/
hmr.js
File metadata and controls
66 lines (55 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var https = require('https');
var express = require('express');
var cors = require('cors')
var app = express();
// Step 1: Create & configure a webpack compiler
var webpack = require('webpack');
const {sign} = require("node:crypto");
var webpackConfig = require('./webpack.config.js')({}, {mode: 'development'});
var compiler = webpack(webpackConfig);
app.use(cors())
// Step 2: Attach the dev middleware to the compiler & the server
app.use(
require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
})
);
// Step 3: Attach the hot middleware to the compiler & the server
app.use(
require('webpack-hot-middleware')(compiler, {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
})
);
const crypto = require('crypto');
const forge = require('node-forge');
const fs = require('fs');
// Generate self-signed certificate
const pki = forge.pki;
const keys = pki.rsa.generateKeyPair(2048);
const cert = pki.createCertificate();
cert.publicKey = keys.publicKey;
cert.serialNumber = '01';
cert.validity.notBefore = new Date();
cert.validity.notAfter = new Date();
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
const attrs = [{
name: 'commonName',
value: 'localhost'
}, {
name: 'organizationName',
value: 'Test'
}];
cert.setSubject(attrs);
cert.setIssuer(attrs);
cert.sign(keys.privateKey);
const options = {
key: forge.pki.privateKeyToPem(keys.privateKey),
cert: forge.pki.certificateToPem(cert)
};
// Do anything you like with the rest of your express application.
var hmr = https.createServer(options, app);
hmr.listen(8090, "127.0.0.1", function () {
console.log('Listening on %j', hmr.address());
});