From f3b10d0b6e11e052682dc503044e27a6cdb81df6 Mon Sep 17 00:00:00 2001 From: John Owens Date: Wed, 9 Oct 2024 13:17:18 -0700 Subject: [PATCH] serve localhost 8000 --- simple_cors_server.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 simple_cors_server.py diff --git a/simple_cors_server.py b/simple_cors_server.py new file mode 100755 index 0000000..f03878c --- /dev/null +++ b/simple_cors_server.py @@ -0,0 +1,17 @@ +#!/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(('localhost', 8000), CORSRequestHandler) +httpd.serve_forever() \ No newline at end of file