MarketDataCollector/simple_server.py
2025-06-09 13:05:31 +08:00

24 lines
743 B
Python

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()