Created
January 19, 2011 04:42
-
-
Save edbo/785696 to your computer and use it in GitHub Desktop.
Snippet demonstrating how to use Node as an https server
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
var crypto = require('crypto'), | |
fs = require('fs'), | |
http = require('http'); | |
var port = 8080; | |
var privateKey = fs.readFileSync('privatekey.pem').toString(), | |
certificate = fs.readFileSync('certificate.pem').toString(); | |
var credentials = crypto.createCredentials({key: privateKey, cert: certificate}); | |
var handler = function(req,res){ | |
res.writeHead(200, {"Content-Type": "text/plain"}); | |
res.end(""); | |
}; | |
var server = http.createServer(); | |
server.setSecure(credentials); | |
server.addListener("request", handler); | |
server.listen(port); | |
console.log("Listening on port: " + port); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment