-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
29 lines (22 loc) · 929 Bytes
/
Copy pathserver.py
File metadata and controls
29 lines (22 loc) · 929 Bytes
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
import os
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
class AppHandler(SimpleHTTPRequestHandler):
def do_GET(self):
if self.path == '/healthz':
self.send_response(200)
self.send_header('Content-type', 'text/plain; charset=utf-8')
self.end_headers()
self.wfile.write(b'ok')
return
if self.path in ('', '/'):
self.path = '/index.html'
# Serve known static files normally; SPA-style fallback to index.html otherwise.
requested = self.path.lstrip('/')
if requested and not os.path.exists(requested):
self.path = '/index.html'
return super().do_GET()
if __name__ == '__main__':
port = int(os.environ.get('PORT', '8080'))
server = ThreadingHTTPServer(('', port), AppHandler)
print(f'ContractorLookup listening on port {port}')
server.serve_forever()