44 lines
1.2 KiB
Python
Executable File
44 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Local dev server for Euchre Scoreboard."""
|
|
|
|
import argparse
|
|
import http.server
|
|
import os
|
|
import socketserver
|
|
import webbrowser
|
|
|
|
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "public")
|
|
DEFAULT_PORT = 20010
|
|
|
|
|
|
class Handler(http.server.SimpleHTTPRequestHandler):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, directory=ROOT, **kwargs)
|
|
|
|
def end_headers(self):
|
|
self.send_header("Cache-Control", "no-cache")
|
|
super().end_headers()
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Run Euchre Scoreboard locally")
|
|
parser.add_argument("-p", "--port", type=int, default=DEFAULT_PORT)
|
|
parser.add_argument("--no-open", action="store_true", help="Do not open a browser tab")
|
|
args = parser.parse_args()
|
|
|
|
url = f"http://localhost:{args.port}"
|
|
|
|
with socketserver.TCPServer(("", args.port), Handler) as httpd:
|
|
print(f"Serving Euchre Scoreboard at {url}")
|
|
print("Press Ctrl+C to stop")
|
|
if not args.no_open:
|
|
webbrowser.open(url)
|
|
try:
|
|
httpd.serve_forever()
|
|
except KeyboardInterrupt:
|
|
print("\nStopped.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|