diff options
Diffstat (limited to 'pyhttpd.py')
-rw-r--r-- | pyhttpd.py | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -1,10 +1,10 @@ #!/usr/bin/env python3 """Use this instead of `python3 -m http.server` when you need CORS""" +import argparse from http.server import HTTPServer, SimpleHTTPRequestHandler from pathlib import Path -serverHost = ('localhost', 8080) class CORSRequestHandler(SimpleHTTPRequestHandler): def end_headers(self): @@ -57,10 +57,18 @@ class CORSRequestHandler(SimpleHTTPRequestHandler): SimpleHTTPRequestHandler.send_error(self, code, message) -httpd = HTTPServer(serverHost, CORSRequestHandler) +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Automaticaly set up a HTTP server') + parser.add_argument('-H', '--host', type=str, default='0.0.0.0', help='Host to serve on') + parser.add_argument('-p', '--port', type=int, default=8080, help='Port to serve on') + args = parser.parse_args() -# Print the server's host and port -print(f"Listening on {serverHost[0]} port {serverHost[1]}") + host, port = args.host, args.port + # Print the server's host and port + print(f"Opening http://{host}:{port}", end='') -httpd.serve_forever() + httpd = HTTPServer((host, port), CORSRequestHandler) + print(f"\rServed on http://{host}:{port}") + + httpd.serve_forever() |