-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
45 lines (30 loc) · 920 Bytes
/
server.py
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
38
39
40
41
42
43
44
45
from http.server import BaseHTTPRequestHandler, HTTPServer
class HTTPRequestHandler(BaseHTTPRequestHandler):
"""Request handler class"""
def do_GET(self):
"""Handler for GET requests"""
# Send response status code
self.send_response(200)
# Send headers
self.send_header("Cache-Control", "no-cache")
if self.path.endswith(".wasm"):
self.send_header("Content-Type", "application/wasm")
else:
self.send_header("Content-Type", "text/html")
self.end_headers()
# Serve the file contents
urlpath = self.path
if urlpath == "/":
urlpath = "/index.html"
with open(f".{urlpath}", "rb") as f:
content = f.read()
self.wfile.write(content)
def main():
print("Starting server...")
# Server settings
server_address = ("localhost", 8080)
httpd = HTTPServer(server_address, HTTPRequestHandler)
print("Running server...")
httpd.serve_forever()
if __name__ == "__main__":
main()