#!/usr/bin/env python3
"""Simple HTTP file server for firmware downloads.

Listens on 0.0.0.0:8089, serves files from the script's directory.
Tailscale Funnel proxies HTTPS traffic here.
"""

import http.server
import os
import sys

PORT = 8089
DIRECTORY = os.path.dirname(os.path.abspath(__file__))


class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, directory=DIRECTORY, **kwargs)


if __name__ == "__main__":
    os.chdir(DIRECTORY)
    with http.server.ThreadingHTTPServer(("0.0.0.0", PORT), Handler) as httpd:
        print(f"Serving {DIRECTORY} on port {PORT}")
        try:
            httpd.serve_forever()
        except KeyboardInterrupt:
            print("\nShutting down.")
            sys.exit(0)
