-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps.js
More file actions
63 lines (50 loc) · 1.4 KB
/
Copy pathhttps.js
File metadata and controls
63 lines (50 loc) · 1.4 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
var fs = require('fs');
var httpProxy = require('http-proxy');
var https = require('https');
var connect = require('connect');
var opn = require('opn');
setTimeout(()=>{
// Create a connect app that can transform the response
var app = connect();
app.use(function (req, res, next) {
if (req.url === '/') {
//util.puts("Transforming response");
var _write = res.write;
// Rewrite the livereload port with our secure one
res.write = function (data) {
_write.call(res, data.toString().replace('35729', '35700'), 'utf8');
}
}
proxy.web(req, res);
}
);
// Proxy fpr connect server to use
var proxy = httpProxy.createServer({
target: {
host: 'localhost',
port: 8100
}
});
// Live reload proxy server
httpProxy.createServer({
target: {
host: 'localhost',
port: 35729
},
ws: true,
ssl: {
// key: fs.readFileSync('server.key', 'utf8'),
// cert: fs.readFileSync('server.crt', 'utf8')
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}
}).listen(35700);
// Create the https server
https.createServer({
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
}, app).listen(8101);
// opens the url in the default browser
opn('https://192.168.2.3:8101');
console.log('http proxy server started on port 8101');
},12000);