Last active
May 5, 2019 22:58
-
-
Save benfluleck/7def82b900b6dffebe202a45b39390cd to your computer and use it in GitHub Desktop.
HTTPS node server
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
var express = require('express'); | |
var app = express(); | |
var fs = require('fs'); | |
var https = require('https'); | |
var key = fs.readFileSync('key.pem'); | |
var cert = fs.readFileSync( 'cert.pem' ); | |
var options = { | |
key: key, | |
cert: cert, | |
passphrase: 'benny' | |
}; | |
app.use('/',(req, res) => { | |
res.writeHead(200); | |
res.end('hello world\n'); | |
}); | |
https.createServer(options, app).listen(443); |
To be able to serve a site on HTTPS from localhost you need to create a self-signed certificate.
A self-signed certificate will be enough to establish a secure HTTPS connection. For development purposes,
I am using a self-signed certificate to achieve this.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365