Last active
March 3, 2020 21:49
-
-
Save luizhenriquefbb/2e1e911a13f952a3242a7b10b3e7618b to your computer and use it in GitHub Desktop.
Simple python working with cors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# encoding: utf-8 | |
"""Use instead of `python3 -m http.server` when you need CORS""" | |
from http.server import HTTPServer, SimpleHTTPRequestHandler | |
import sys | |
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() | |
PORT = int(sys.argv[1]) | |
httpd = HTTPServer(('localhost', PORT), CORSRequestHandler) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment