-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps-proxy.js
More file actions
29 lines (26 loc) · 833 Bytes
/
https-proxy.js
File metadata and controls
29 lines (26 loc) · 833 Bytes
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
const https = require('https');
const http = require('http');
const fs = require('fs');
// Simple HTTPS reverse proxy to localhost:3000
const options = {
key: fs.readFileSync('/home/moltbot/ssl/key.pem'),
cert: fs.readFileSync('/home/moltbot/ssl/cert.pem')
};
const server = https.createServer(options, (req, res) => {
// Forward to local HTTP server
const proxyReq = http.request({
hostname: '127.0.0.1',
port: 3000,
path: req.url,
method: req.method,
headers: req.headers
}, (proxyRes) => {
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);
});
proxyReq.on('error', () => res.end('Backend unavailable'));
req.pipe(proxyReq);
});
server.listen(3443, '0.0.0.0', () => {
console.log('HTTPS proxy running on https://0.0.0.0:3443 → http://localhost:3000');
});