Created
November 15, 2022 00:35
-
-
Save techforum-repo/dc4d044f523d98588c416055c7cf28e2 to your computer and use it in GitHub Desktop.
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
import os | |
import sys | |
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
import ssl | |
PORT = 443 | |
class HTTPRequestHandler(SimpleHTTPRequestHandler): | |
def end_headers(self): | |
self.send_header('Access-Control-Allow-Origin', '*') | |
SimpleHTTPRequestHandler.end_headers(self) | |
def server(port): | |
httpd = HTTPServer(('', port), HTTPRequestHandler) | |
httpd.socket = ssl.wrap_socket (httpd.socket, keyfile="SSL/server.key", certfile='SSL/server.crt', server_side=True) | |
return httpd | |
if __name__ == "__main__": | |
port = PORT | |
httpd = server(port) | |
try: | |
os.chdir('data') | |
print("\nserving from data/ at localhost:" + str(port)) | |
httpd.serve_forever() | |
except KeyboardInterrupt: | |
print("\n...shutting down http server") | |
httpd.shutdown() | |
sys.exit() |
Author
techforum-repo
commented
Nov 15, 2022
Refer to https://betterprogramming.pub/trusted-self-signed-certificate-and-local-domains-for-testing-7c6e6e3f9548 for details on generating self signed SSL certificate.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment