Skip to content

Instantly share code, notes, and snippets.

@leigh-johnson
Last active May 23, 2017 17:35
Show Gist options
  • Save leigh-johnson/b8672cacd5e63c8254cda6bf9dbb607c to your computer and use it in GitHub Desktop.
Save leigh-johnson/b8672cacd5e63c8254cda6bf9dbb607c to your computer and use it in GitHub Desktop.
Quick and dirty HTTPS servers (Python 3+ and NodeJS 6.9.1+)
const https = require('https');
const fs = require('fs');
// Do you need to create a self-signed certificate?
// $ brew install openssl
// $ openssl req -new -x509 -keyout localhost.key -out localhost.crt -days 365 -nodes
// Do you need a certificate signed by a trusted authority?
// Check out https://letsencrypt.org/getting-started/
const options = {
key: fs.readFileSync('localhost.key'),
cert: fs.readFileSync('localhost.crt')
};
https.createServer(options, (req, res) => {
res.writeHead(200);
console.log(req)
}).listen(5443);
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
# Do you need to create a self-signed certificate?
# $ brew install openssl
# $ openssl req -new -x509 -keyout localhost.pem -out localhost.pem -days 365 -nodes
# Do you need a certificate signed by a trusted authority?
# Check out https://letsencrypt.org/getting-started/
CONNECTION = {'host': 'localhost' ,'port': 5443}
class JankHandler(BaseHTTPRequestHandler):
pass
httpd = HTTPServer((CONNECTION['host'], CONNECTION['port']), JankHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile='localhost.pem', server_side=True)
print('Serving https://{host}:{port}'.format(**CONNECTION))
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment