From dd5767696346c7861e29ba09718cfef741e1dbc8 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 21 Apr 2023 03:40:54 +0200 Subject: Add pyhttpd --- Makefile | 2 +- pyhttpd.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 pyhttpd.py 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() -- cgit v1.2.3