Skip to content

Instantly share code, notes, and snippets.

@joewalnes
Created February 18, 2011 12:36
Show Gist options
  • Save joewalnes/833611 to your computer and use it in GitHub Desktop.
Save joewalnes/833611 to your computer and use it in GitHub Desktop.
Connect and HTTPS
== In earlier versions of Node, HTTPS with Connect was easy ==
var server = connect.createServer(middleware1, middleware2,...);
server.setSecure(crypto.createCredentials({
key: myHttpsKey,
cert: myHttpsCert
}));
server.listen(port);
== Since HTTPS has been split into a new module, it's more awkward ==
I ended up doing this...
var ConnectHttpsServer = function(layers) {
this.stack = [];
// Stack layers
layers.forEach(function(layer){
this.use("/", layer);
}, this);
// Set up the request handler using the parent's constructor
https.Server.call(this, {
key: myHttpsKey,
cert: myHttpCert
}, this.handle);
};
ConnectHttpsServer.prototype.__proto__ = https.Server.prototype;
ConnectHttpsServer.prototype.use = connect.Server.prototype.use;
ConnectHttpsServer.prototype.handle = connect.Server.prototype.handle;
var server = new ConnectHttpsServer(middleware1, middleware2,...);
server.listen(port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment