-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev_server.py
More file actions
25 lines (20 loc) · 742 Bytes
/
Copy pathdev_server.py
File metadata and controls
25 lines (20 loc) · 742 Bytes
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
import http.server
import socketserver
import os
PORT = 8000
class GitHubPagesHandler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
# Base translation
filepath = super().translate_path(path)
# If the requested path is not found directly, try appending .html
if not os.path.exists(filepath):
if os.path.exists(filepath + '.html'):
return filepath + '.html'
return filepath
if __name__ == '__main__':
with socketserver.TCPServer(("", PORT), GitHubPagesHandler) as httpd:
print(f"Serving at http://localhost:{PORT}")
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass