import http.server import socketserver import os PORT = 9080 DIRECTORY = "C:/LocalLoopWeb/" class CustomHandler(http.server.SimpleHTTPRequestHandler): def translate_path(self, path): # Get the full file path from the requested path full_path = os.path.abspath(os.path.join(DIRECTORY, path.lstrip('/'))) # Verify that the file path is within the allowed directory if not full_path.startswith(os.path.abspath(DIRECTORY)): self.send_error(404, "File not found") return None return full_path Handler = CustomHandler httpd = socketserver.TCPServer(("127.0.0.1", PORT), Handler) httpd.allow_reuse_address = True print(f"Serving HTTP on 127.0.0.1 port {PORT} (http://127.0.0.1:{PORT}/)") httpd.serve_forever()