Skip to content

Commit cfe522b

Browse files
authored
Fix resolve 404 errors when running server from absolute path (#57)
1 parent 0b31310 commit cfe522b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

visualizer/server.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ def load_config():
8484
"api": {"base_url": "http://localhost:8000/api"}
8585
}
8686

87+
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
8788
class IRISVisualizerHandler(http.server.SimpleHTTPRequestHandler):
8889
def __init__(self, *args, **kwargs):
89-
super().__init__(*args, directory=os.getcwd(), **kwargs)
90+
server_root = os.path.dirname(os.path.abspath(__file__))
91+
super().__init__(*args, directory=server_root, **kwargs)
9092

9193
def do_GET(self):
9294
"""Handle GET requests"""
@@ -123,7 +125,7 @@ def do_GET(self):
123125

124126
# Read and send file content
125127
try:
126-
file_path = os.path.join(os.getcwd(), path.lstrip('/'))
128+
file_path = os.path.join(BASE_DIR, path.lstrip('/'))
127129
if os.path.exists(file_path):
128130
with open(file_path, 'rb') as f:
129131
self.wfile.write(f.read())

0 commit comments

Comments
 (0)