#!/usr/bin/env python3 """ serve.py -- launch the DPL3 scene archive locally. The archive viewer lazy-loads scene JSON via fetch(), which browsers block over file://. This serves the viewer/ folder over http so it works. Run it, then the browser opens automatically. Threaded (parallel requests don't queue behind a large scene download) and sends Cache-Control: no-store so a truncated response can never be cached and replayed by the browser. python viewer/serve.py """ import http.server import os import webbrowser PORT = 8765 os.chdir(os.path.dirname(os.path.abspath(__file__))) class Handler(http.server.SimpleHTTPRequestHandler): def end_headers(self): self.send_header("Cache-Control", "no-store") super().end_headers() def log_message(self, fmt, *args): # quieter console pass url = "http://localhost:%d/archive.html" % PORT print("DPL3 scene archive -> %s (Ctrl+C to stop)" % url) try: webbrowser.open(url) except Exception: pass with http.server.ThreadingHTTPServer(("", PORT), Handler) as httpd: try: httpd.serve_forever() except KeyboardInterrupt: print("\nstopped")