#!/usr/bin/env python3 """Simple dev server for testing Ritz components.""" import http.server import socketserver from pathlib import Path PORT = 8111 DIRECTORY = Path(__file__).parent / "examples" class WASMHandler(http.server.SimpleHTTPRequestHandler): """HTTP handler with proper WASM MIME type.""" def __init__(self, *args, **kwargs): super().__init__(*args, directory=str(DIRECTORY), **kwargs) def end_headers(self): # Set CORS headers for local development self.send_header("Access-Control-Allow-Origin", "*") # Ensure WASM has correct MIME type if self.path.endswith(".wasm"): self.send_header("Content-Type", "application/wasm") super().end_headers() if __name__ == "__main__": socketserver.TCPServer.allow_reuse_address = True with socketserver.TCPServer(("", PORT), WASMHandler) as httpd: print("šŸš€ Ritz Dev Server") print(f" Serving: {DIRECTORY}") print(f" URL: http://localhost:{PORT}") print(f"\n Open http://localhost:{PORT}/index.html in your browser") print("\n Press Ctrl+C to stop") try: httpd.serve_forever() except KeyboardInterrupt: print("\n\nšŸ‘‹ Server stopped")