Skip to content

Instantly share code, notes, and snippets.

@jamchamb
Created July 18, 2017 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamchamb/741a3f139d9a93cd8908f4888b151913 to your computer and use it in GitHub Desktop.
Save jamchamb/741a3f139d9a93cd8908f4888b151913 to your computer and use it in GitHub Desktop.
Simple Node HTTPS server
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