import os
import http.server
import socketserver
from pathlib import Path

PORT = 18181
HOST = "0.0.0.0"
HTML_FILE = "canvas_slot_machine_clicky_sound.html"

if not Path(HTML_FILE).exists():
    raise FileNotFoundError(f"{HTML_FILE} not found in {os.getcwd()}")

class ReusableTCPServer(socketserver.TCPServer):
    allow_reuse_address = True

handler = http.server.SimpleHTTPRequestHandler

with ReusableTCPServer((HOST, PORT), handler) as httpd:
    print(f"Serving folder: {os.getcwd()}")
    print(f"Open: http://localhost:{PORT}/{HTML_FILE}")
    print("Press Ctrl+C to stop.")
    httpd.serve_forever()
