#!/usr/bin/env python3
"""HTTP server for the WebShare file:// MojoJS POC. Serves on 127.0.0.1:8080."""
import http.server
import socketserver
import os

PORT = 8404
ROOT = os.path.dirname(os.path.abspath(__file__))


class Handler(http.server.SimpleHTTPRequestHandler):
    def __init__(self, *a, **kw):
        super().__init__(*a, directory=ROOT, **kw)

    def end_headers(self):
        # Disable caching so the POC can be edited and re-run without restart.
        self.send_header("Cache-Control", "no-store")
        super().end_headers()


if __name__ == "__main__":
    socketserver.TCPServer.allow_reuse_address = True
    with socketserver.TCPServer(("127.0.0.1", PORT), Handler) as httpd:
        print(f"[*] serving {ROOT} on http://127.0.0.1:{PORT}/poc.html")
        httpd.serve_forever()
