feat: initial release of FlockRadar driving app and national transparency directory for flockradar.org
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import http.server
|
||||
import socketserver
|
||||
import ssl
|
||||
import threading
|
||||
import sys
|
||||
import os
|
||||
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
class NoCacheHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def end_headers(self):
|
||||
self.send_header('Cache-Control', 'no-cache, no-store, must-revalidate')
|
||||
self.send_header('Pragma', 'no-cache')
|
||||
self.send_header('Expires', '0')
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
super().end_headers()
|
||||
|
||||
def run_http(port=8085):
|
||||
try:
|
||||
class ReusableServer(socketserver.TCPServer):
|
||||
allow_reuse_address = True
|
||||
with ReusableServer(('', port), NoCacheHandler) as httpd:
|
||||
print(f'Serving HTTP on port {port} (http://localhost:{port} and http://192.168.1.249:{port})')
|
||||
sys.stdout.flush()
|
||||
httpd.serve_forever()
|
||||
except Exception as e:
|
||||
print(f'HTTP Server on {port} notice: {e}')
|
||||
sys.stdout.flush()
|
||||
|
||||
def run_https(port=8443):
|
||||
try:
|
||||
class ReusableServer(socketserver.TCPServer):
|
||||
allow_reuse_address = True
|
||||
with ReusableServer(('', port), NoCacheHandler) as httpd:
|
||||
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
|
||||
ctx.load_cert_chain(certfile='cert.pem', keyfile='key.pem')
|
||||
httpd.socket = ctx.wrap_socket(httpd.socket, server_side=True)
|
||||
print(f'Serving HTTPS on port {port} (https://localhost:{port} and https://192.168.1.249:{port})')
|
||||
sys.stdout.flush()
|
||||
httpd.serve_forever()
|
||||
except Exception as e:
|
||||
print(f'HTTPS Server on {port} notice: {e}')
|
||||
sys.stdout.flush()
|
||||
|
||||
if __name__ == '__main__':
|
||||
t_https = threading.Thread(target=run_https, args=(8443,), daemon=True)
|
||||
t_https.start()
|
||||
run_http(8085)
|
||||
Reference in New Issue
Block a user