simple server
This commit is contained in:
parent
14272ab6eb
commit
245ded50ef
24
simple_server.py
Normal file
24
simple_server.py
Normal file
@ -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()
|
||||||
Loading…
x
Reference in New Issue
Block a user