Skip to content

Instantly share code, notes, and snippets.

@fjakobs
Created July 16, 2012 19:00
Show Gist options
  • Save fjakobs/3124364 to your computer and use it in GitHub Desktop.
Save fjakobs/3124364 to your computer and use it in GitHub Desktop.
SSL termination proxy
var tls = require("tls");
var net = require("net");
var fs = require("fs");
var host = "c9.dev";
tls.createServer({
key: fs.readFileSync(__dirname + "/key.pem"),
cert: fs.readFileSync(__dirname + "/cert.pem")
}, function(client) {
var socket = new net.Socket();
socket.connect(80, host);
client.pipe(socket, { end: false });
socket.pipe(client);
}).listen(443, host);
console.log("Listening at", host, 443);
@piscisaureus
Copy link

  • You need error handling.
  • Try to run this with node master and enjoy the performance bump :-)

@fjakobs
Copy link
Author

fjakobs commented Jul 16, 2012

How would I do proper error handling?

@piscisaureus
Copy link

client.on('error', ...
socket.on('error', ...

@fjakobs
Copy link
Author

fjakobs commented Jul 17, 2012

right, but what to do with them? Log and ignore so that the app will at least not terminate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment