-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
34 lines (28 loc) · 960 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
import os, sys
import socketserver
import ssl
from request_handler import RequestHandler
from pksroutes import *
def main():
bindPort = int(os.getenv("PORT", 8080))
tlsEnabled = bool(os.getenv("TLS_ENABLED", False) == "true")
tlsCertPath = str(os.getenv("TLS_CERT_PATH"))
tlsKeyPath = str(os.getenv("TLS_KEY_PATH"))
Handler = RequestHandler
with socketserver.TCPServer(("0.0.0.0", bindPort), Handler) as httpd:
print("Serving at port", bindPort)
if (tlsEnabled):
httpd.socket = ssl.wrap_socket(httpd.socket,
keyfile=tlsKeyPath,
certfile=tlsCertPath, server_side=True)
try:
httpd.serve_forever()
except BaseException as e:
print("Stop server. Error: ", e)
httpd.server_close()
try:
sys.exit(0)
except SystemExit:
os._exit(0)
if __name__ == '__main__':
main()