RaspberryPi4b/SourceCode-NAS-Olivito_Gian...

26 lines
693 B
Python

# Import libraries
import http.server
import socketserver
import os
# Define port and path to external drive directory
port = 8000
directory = "/media/gianluca/Elements"
class MyHandler(http.server.SimpleHTTPRequestHandler):
def translatePath(self, path):
# Modify default behavior of SimpleHTTPRequestHandler
path = super().translate_path(path)
# Ensure correct path handling by joining directories
if not path.startswith(directory):
path = os.path.join(directory, path.lstrip("/"))
return path
handler = MyHandler
httpd = socketserver.TCPServer(("", port), handler)
print(f"Serving on port {port}")
httpd.serve_forever()