-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
26 lines (21 loc) · 904 Bytes
/
index.js
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
const https = require('https'),
httpProxy = require('http-proxy');
const createProxyServer = (privateKey, certificate, passphrase, target, whitelist) => {
const credentials = { key: privateKey, cert: certificate, passphrase };
const proxy = httpProxy.createServer({
changeOrigin: true,
ssl: credentials,
secure: true,
});
const server = https.createServer({ ...credentials, rejectUnauthorized: false }, (req, res) => {
if (whitelist.indexOf(req.socket.remoteAddress) >= 0) {
proxy.web(req, res, { target: target, changeOrigin: true });
console.log(`User IP: ${req.socket.remoteAddress} was accessed.`);
} else {
res.end("Sorry, You are not in whitelist");
console.log(`User IP: ${req.socket.remoteAddress} was kicked.`)
}
})
return server
}
module.exports = createProxyServer