diff options
author | ache <ache@ache.one> | 2023-04-21 03:40:54 +0200 |
---|---|---|
committer | ache <ache@ache.one> | 2023-04-21 03:40:54 +0200 |
commit | dd5767696346c7861e29ba09718cfef741e1dbc8 (patch) | |
tree | 59e25bb66b8ffdf77a25e6149998344a82b8c0f8 /pyhttpd.py | |
parent | Add types to function (diff) |
Add pyhttpd
Diffstat (limited to 'pyhttpd.py')
-rw-r--r-- | pyhttpd.py | 16 |
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() |