swimtracker-app/old-site/serve2.py

20 lines
642 B
Python
Raw Normal View History

2020-06-05 21:43:17 +02:00
#!/usr/bin/env python3
# encoding: utf-8
"""Use instead of `python3 -m http.server` when you need CORS"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET')
self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
return super(CORSRequestHandler, self).end_headers()
httpd = HTTPServer(('0.0.0.0', 8003), CORSRequestHandler)
print("serving on http://localhost:8003/")
httpd.serve_forever()