forked from teorth/analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.py
More file actions
30 lines (25 loc) · 1.1 KB
/
serve.py
File metadata and controls
30 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from http.server import SimpleHTTPRequestHandler, HTTPServer
BOOK_SITE = os.path.abspath('./book/_site')
DOCS_SITE = os.path.abspath('./analysis/.lake/build/doc')
class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):
def translate_path(self, path):
# Serve /analysis-book/docs/* from DOCS_SITE
if path.startswith('/analysis/docs/'):
rel_path = path[len('/analysis/docs/'):]
return os.path.join(DOCS_SITE, rel_path)
# Serve /analysis-book/* from BOOK_SITE
elif path.startswith('/analysis/'):
rel_path = path[len('/analysis/'):]
return os.path.join(BOOK_SITE, rel_path)
# Otherwise, serve nothing (could return a non-existent path)
else:
raise FileNotFoundError("File not found")
if __name__ == '__main__':
PORT = 8000
handler = CustomHTTPRequestHandler
with HTTPServer(("", PORT), handler) as httpd:
print(f"Serving at http://localhost:{PORT}/analysis")
print(f"/analysis: {BOOK_SITE}")
print(f"/analysis/docs: {DOCS_SITE}")
httpd.serve_forever()