forked from Viraj3f/QFace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
96 lines (87 loc) · 2.86 KB
/
server.py
File metadata and controls
96 lines (87 loc) · 2.86 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import http.server
import socketserver
class TurboServer(http.server.SimpleHTTPRequestHandler):
paths = {
# General purpose routes
"/": {
"content-type": "html",
"filename": "src/views/index.html",
"response_code": 200
},
"/addCustomer": {
"content-type": "html",
"filename": "src/views/addCustomer.html",
"response_code": 200
},
"/identifyCustomer": {
"content-type": "html",
"filename": "src/views/identifyCustomer.html",
"response_code": 200
},
"/saveCustomer": {
"content-type": "html",
"filename": "src/views/saveCustomer.html",
"response_code": 200
},
"/showCustomer": {
"content-type": "html",
"filename": "src/views/showCustomer.html",
"response_code": 200
},
"/Turbo.asm.js": {
"content-type": "application/javascript",
"filename": "bin/Turbo.asm.js",
"response_code": 200
},
"/Turbo.asm.data": {
"content-type": "application/javascript",
"filename": "bin/Turbo.asm.data",
"response_code": 200
},
"/Turbo.asm.wasm": {
"content-type": "application/javascript",
"filename": "bin/Turbo.asm.wasm",
"response_code": 200
},
# Custom routes for tests
"/Turbo.asm.js.mem": {
"content-type": "application/javascript",
"filename": "bin/Turbo.asm.js.mem",
"response_code": 200
},
"/Turbo.test.data": {
"content-type": "application/javascript",
"filename": "bin/Turbo.test.data",
"response_code": 200
},
"/Turbo.test.js": {
"content-type": "application/javascript",
"filename": "bin/Turbo.test.js",
"response_code": 200
},
"/test": {
"content-type": "html",
"filename": "src/views/test.html",
"response_code": 200
}
}
def do_GET(self):
raw_path = self.path.split("?")[0]
if raw_path in TurboServer.paths:
route_options = TurboServer.paths[raw_path]
self.send_response(route_options["response_code"])
self.send_header('content-type', route_options["content-type"])
self.end_headers()
file_content = open(route_options["filename"], "rb").read()
self.wfile.write(file_content)
else:
super().do_GET()
def run():
print("Starting server at: http://localhost:8080")
httpd = socketserver.TCPServer(('localhost', 8080), TurboServer)
try:
httpd.serve_forever()
except KeyboardInterrupt:
httpd.server_close()
if __name__ == "__main__":
run()