Adapt path handling
parent
f9e6f5e9e1
commit
b394aea469
|
@ -1,19 +1,25 @@
|
|||
# Import libraries
|
||||
import http.server
|
||||
import socketserver
|
||||
import os
|
||||
|
||||
# Define port and path tho external drive directory
|
||||
PORT = 8000
|
||||
DIRECTORY = "/mnt/mydisk"
|
||||
# Define port and path to external drive directory
|
||||
port = 8000
|
||||
directory = "/media/gianluca/Elements"
|
||||
|
||||
class MyHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def translatePath(self, path):
|
||||
# Modifizieren des Standardverhaltens von SimpleHTTPRequestHandler
|
||||
|
||||
# Modify default behavior of SimpleHTTPRequestHandler
|
||||
path = super().translate_path(path)
|
||||
return path if path.startswith(DIRECTORY) else DIRECTORY + 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)
|
||||
httpd = socketserver.TCPServer(("", port), handler)
|
||||
|
||||
print(f"Serving on port {PORT}")
|
||||
print(f"Serving on port {port}")
|
||||
httpd.serve_forever()
|
Loading…
Reference in New Issue