• expects a cert.pem and key.pem in the PWD

  • a passphrase for the cert.pem can ge added as an extra arg to the load_cert_chain(password=“pwd”)

from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
from pathlib import Path

port = 443

httpd = HTTPServer(("0.0.0.0", port), SimpleHTTPRequestHandler)
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(Path(__file__).parent / "cert.pem", keyfile=Path(__file__).parent / "key.pem")
httpd.socket = ssl_context.wrap_socket(
    httpd.socket,
    server_side=True,
)

print(f"Serving on https://localhost:{port}")
httpd.serve_forever()