import http.server, socketserver, functools, sys

class H(http.server.SimpleHTTPRequestHandler):
    def log_message(self, *a): pass
    def end_headers(self):
        self.send_header('Cache-Control', 'no-store')
        # The README embeds the viewer as a srcdoc iframe sandboxed WITHOUT allow-same-origin,
        # so it runs at an opaque origin and every fetch it makes is cross-origin. The wiki's
        # blob host sends permissive CORS; mirror that here or the bundle fetch ERR_FAILEDs.
        self.send_header('Access-Control-Allow-Origin', '*')
        super().end_headers()

socketserver.ThreadingTCPServer.allow_reuse_address = True
d = sys.argv[1]; p = int(sys.argv[2])
with socketserver.ThreadingTCPServer(('127.0.0.1', p), functools.partial(H, directory=d)) as s:
    print('serving', d, 'on', p, flush=True)
    s.serve_forever()
