diff --git a/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py b/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py index 449a0b6..3649b66 100644 --- a/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py +++ b/SourceCode-NAS-Olivito_Gianluca_CDS205_HS24.py @@ -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}") -httpd.serve_forever() \ No newline at end of file +print(f"Serving on port {port}") +httpd.serve_forever()