Skip to content

Instantly share code, notes, and snippets.

@luizhenriquefbb
Last active March 3, 2020 21:49
Show Gist options
  • Save luizhenriquefbb/2e1e911a13f952a3242a7b10b3e7618b to your computer and use it in GitHub Desktop.
Save luizhenriquefbb/2e1e911a13f952a3242a7b10b3e7618b to your computer and use it in GitHub Desktop.
Simple python working with cors
#!/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