Skip to content

Instantly share code, notes, and snippets.

Forked from dergachev/
Last active February 18, 2021 01:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env python
# Based on
# generate server.pem with the following command:
# openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
# run as follows:
# python
# then in your browser, visit:
# https://localhost:4443
import argparse
import BaseHTTPServer, SimpleHTTPServer
import ssl
import os
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--host', type=str, default='localhost')
parser.add_argument('--port', type=int, default=4443)
parser.add_argument('--srvdir', type=str, default=None)
args = parser.parse_args()
base_dir = os.path.realpath(os.path.dirname(__file__))
cert_path = os.path.join(base_dir, 'server.pem')
if args.srvdir is None:
web_dir = os.path.join(base_dir, 'web')
web_dir = args.srvdir
httpd = BaseHTTPServer.HTTPServer((, args.port), SimpleHTTPServer.SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket (httpd.socket, certfile=cert_path, server_side=True)
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment