init
This commit is contained in:
commit
97f9a95415
21 changed files with 2963 additions and 0 deletions
24
dev_server.py
Executable file
24
dev_server.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
import http.server, socketserver, os, pathlib
|
||||
|
||||
ROOT = pathlib.Path(__file__).parent / 'public'
|
||||
PORT = int(os.environ.get('PORT', '8008'))
|
||||
|
||||
class SPAHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
path_only = self.path.split('?',1)[0].split('#',1)[0]
|
||||
fs_path = self.translate_path(path_only)
|
||||
if os.path.exists(fs_path) and os.path.isfile(fs_path):
|
||||
return super().do_GET()
|
||||
self.path = '/index.html'
|
||||
return super().do_GET()
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir(ROOT) # serve from /public
|
||||
with socketserver.TCPServer(('127.0.0.1', PORT), SPAHandler) as httpd:
|
||||
print(f"Serving {ROOT} at http://127.0.0.1:{PORT}")
|
||||
try:
|
||||
httpd.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue