#!/usr/bin/env python3 """ Simple HTTP server for testing the Text Corruptor PWA Run with: python3 server.py Then open http://localhost:8000/ in your browser """ import http.server import socketserver import os PORT = 8000 # Serve from the app directory DIRECTORY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "app") class MyHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): """Custom HTTP request handler for serving the Text Corruptor PWA.""" def __init__(self, *args, **kwargs): super().__init__(*args, directory=DIRECTORY, **kwargs) def end_headers(self): # Add headers for PWA and CORS self.send_header("Cache-Control", "no-cache, no-store, must-revalidate") self.send_header("Service-Worker-Allowed", "/") self.send_header("X-Content-Type-Options", "nosniff") super().end_headers() if __name__ == "__main__": with socketserver.TCPServer(("", PORT), MyHTTPRequestHandler) as httpd: print(f"Server running at http://localhost:{PORT}/") print(f"Serving files from: {DIRECTORY}") print("Press Ctrl+C to stop the server") try: httpd.serve_forever() except KeyboardInterrupt: print("\nServer stopped.")