Created
July 18, 2017 18:37
-
-
Save jamchamb/741a3f139d9a93cd8908f4888b151913 to your computer and use it in GitHub Desktop.
Simple Node 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
const tls = require('tls') | |
const fs = require("fs") | |
const https = require("https") | |
/* | |
$ openssl req -newkey rsa:2048 -new -nodes -x509 -days 365 \ | |
-keyout key.pem -out cert.pem | |
*/ | |
const options = { | |
key: fs.readFileSync('key.pem'), | |
cert: fs.readFileSync('csr.pem') | |
} | |
const handler = function (req, res) { | |
res.writeHead(200, { | |
'Content-Type': 'text/html', | |
'Access-Control-Allow-Origin': '*', | |
}) | |
res.end('<h2>Content</h2>\n') | |
}; | |
const server = https.createServer(options, handler) | |
server.listen(4443) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment