Created
April 19, 2023 06:19
-
-
Save Raaghu/5ac62669d9ff71a0fbb98f74b33ae57a to your computer and use it in GitHub Desktop.
Do you want to enable SSL for your server runnning in port 80 ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const tls = require('tls'); | |
const net = require('net'); | |
const server = tls | |
.createServer( | |
{ | |
key: fs.readFileSync('/opt/ssl/certs/key.pem'), | |
cert: fs.readFileSync('/opt/ssl/certs/cert.pem'), | |
}, | |
clientToProxySocket => { | |
const proxyToServerSocket = net.createConnection( | |
{host: 'localhost', port: '80'}, | |
() => { | |
clientToProxySocket.pipe(proxyToServerSocket); | |
proxyToServerSocket.pipe(clientToProxySocket); | |
}, | |
); | |
}, | |
) | |
.listen(443); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# start the original server in background | |
npm start & | |
# start the node-ssl-proxy | |
node ./node-ssl-proxy.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment