20 lines
642 B
Python
20 lines
642 B
Python
|
|
||
|
#!/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()
|