aboutsummaryrefslogtreecommitdiff
path: root/pyhttpd.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyhttpd.py')
-rw-r--r--pyhttpd.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/pyhttpd.py b/pyhttpd.py
new file mode 100644
index 0000000..2ca1eda
--- /dev/null
+++ b/pyhttpd.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+"""Use this 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', '*')
+ self.send_header('Cache-Control', 'no-store, no-cache, must-revalidate')
+ return super(CORSRequestHandler, self).end_headers()
+
+
+httpd = HTTPServer(('localhost', 8080), CORSRequestHandler)
+httpd.serve_forever()