Created
February 18, 2011 12:36
-
-
Save joewalnes/833611 to your computer and use it in GitHub Desktop.
Connect and HTTPS
This file contains 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
== 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