diff --git a/simple_server.py b/simple_server.py new file mode 100644 index 0000000..466d4d5 --- /dev/null +++ b/simple_server.py @@ -0,0 +1,24 @@ +import http.server +import os + +PORT = 8050 +DIRECTORY = "./data/db" + +class CustomHandler(http.server.SimpleHTTPRequestHandler): + def translate_path(self, path): + # Serve files from the specified directory + path = super().translate_path(path) + return os.path.join(DIRECTORY, os.path.relpath(path, os.path.dirname(path))) + +def run(server_class=http.server.HTTPServer, handler_class=CustomHandler): + server_address = ("", PORT) + httpd = server_class(server_address, handler_class) + print(f"Serving on port {PORT}... Press Ctrl-C to stop.") + try: + while True: + httpd.handle_request() + except KeyboardInterrupt: + print("\nServer stopped by user.") + +if __name__ == "__main__": + run() \ No newline at end of file