-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduo_server.py
More file actions
47 lines (36 loc) · 1.24 KB
/
duo_server.py
File metadata and controls
47 lines (36 loc) · 1.24 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
from http.server import BaseHTTPRequestHandler, HTTPServer
import json
import sys
hostName = "0.0.0.0"
serverPort = 7000
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == "/duo_user_info.json":
self.send_response(200)
self.send_header("Content-type", "text/json")
self.end_headers()
with open("duo_user_info.json", "rb") as file:
self.wfile.write(file.read())
elif self.path == "/health":
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
response_content = {
"code": 200,
"message": "I'm alive!"
}
response_json = json.dumps(response_content)
self.wfile.write(response_json.encode("utf-8"))
else:
self.send_response(403)
self.end_headers()
def run_server():
print("Server started.")
web_server = HTTPServer((hostName, serverPort), MyServer)
try:
web_server.serve_forever()
except KeyboardInterrupt:
pass
web_server.server_close()
print("Server stopped.")
run_server()