DEV Community

Raghavendra
Raghavendra

Posted on

SSL Wrapper on existing HTTP server

There are many scenarios where the Application is running in port 80 and we need to enable SSL on that. Each frameworks/languages provides a different ways to enable the HTTPS.

In this gist I created a small reverse-proxy server which handles the HTTPS connection and redirects to HTTP server internally

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);
# start the original server in background
npm start &
# start the node-ssl-proxy
node ./node-ssl-proxy.js
view raw start.sh hosted with ❤ by GitHub

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay