-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathserver.py
More file actions
37 lines (27 loc) · 1.06 KB
/
Copy pathserver.py
File metadata and controls
37 lines (27 loc) · 1.06 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
30
31
32
33
34
35
36
37
# Firebase does not allow running hosting locally without
# having permission to access the production server
# This script copies the behaviour of the configuration in
# firebase.json, but allows it to run locally without permissions
from http.server import SimpleHTTPRequestHandler, HTTPServer
import re
class RequestHandler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, directory="public")
def end_headers(self):
self.send_header("Cache-Control", "no-cache, must-revalidate")
super().end_headers()
def do_GET(self):
if self.path.startswith("/pipescore"):
self.path = "/pipescore.html"
elif self.path == "/":
self.path = "/index.html"
elif "." not in re.search("(/.*?)$", self.path).group(0):
self.path += ".html"
return super().do_GET()
def run():
addr = ("", 8000)
server = HTTPServer(addr, RequestHandler)
print("Serving on localhost:8000")
server.serve_forever()
if __name__ == "__main__":
run()