From 245ded50eff453ac1292d31ea24a188b0e545254 Mon Sep 17 00:00:00 2001 From: "Vasily.onl" Date: Mon, 9 Jun 2025 13:05:31 +0800 Subject: [PATCH] simple server --- simple_server.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 simple_server.py 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