aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2023-04-21 03:40:54 +0200
committerache <ache@ache.one>2023-04-21 03:40:54 +0200
commitdd5767696346c7861e29ba09718cfef741e1dbc8 (patch)
tree59e25bb66b8ffdf77a25e6149998344a82b8c0f8
parentAdd types to function (diff)
Add pyhttpd
-rw-r--r--Makefile2
-rw-r--r--pyhttpd.py16
2 files changed, 17 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 3d497ce..d77e953 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-INSTALL_LIST=autoDHCP.sh autoWall.sh cmount.sh coWifi.sh cumount.sh imgs2pdf.sh light2.sh toMp3.sh bot4chan.py track.py autoMMS.py
+INSTALL_LIST=autoDHCP.sh autoWall.sh cmount.sh coWifi.sh cumount.sh imgs2pdf.sh light2.sh toMp3.sh bot4chan.py track.py autoMMS.py pyhttpd.py
install:
@if [ -z $(filter-out $@,$(MAKECMDGOALS)) ] ; then \
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()