Staticaliza commited on
Commit
e5d371d
·
verified ·
1 Parent(s): fdcd9d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -8,13 +8,11 @@ print("HI")
8
 
9
  def start_https():
10
  https_port = int(os.getenv("HTTPS_PORT", "8443"))
 
 
 
11
  httpd = HTTPServer(("0.0.0.0", https_port), SimpleHTTPRequestHandler)
12
- httpd.socket = ssl.wrap_socket(
13
- httpd.socket,
14
- certfile="cert.pem",
15
- keyfile="key.pem",
16
- server_side=True
17
- )
18
  print(f"https listening on 0.0.0.0:{https_port}")
19
  httpd.serve_forever()
20
 
@@ -32,7 +30,6 @@ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
32
  sock.bind(("0.0.0.0", port))
33
  sock.listen()
34
  print(f"listening on 0.0.0.0:{port}")
35
-
36
  while True:
37
  conn, addr = sock.accept()
38
  print("connection from", addr)
 
8
 
9
  def start_https():
10
  https_port = int(os.getenv("HTTPS_PORT", "8443"))
11
+ # create ssl context
12
+ context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
13
+ context.load_cert_chain("cert.pem", "key.pem")
14
  httpd = HTTPServer(("0.0.0.0", https_port), SimpleHTTPRequestHandler)
15
+ httpd.socket = context.wrap_socket(httpd.socket, server_side=True)
 
 
 
 
 
16
  print(f"https listening on 0.0.0.0:{https_port}")
17
  httpd.serve_forever()
18
 
 
30
  sock.bind(("0.0.0.0", port))
31
  sock.listen()
32
  print(f"listening on 0.0.0.0:{port}")
 
33
  while True:
34
  conn, addr = sock.accept()
35
  print("connection from", addr)