Skip to content

Instantly share code, notes, and snippets.

@ajesler
Created August 12, 2017 21:15
Show Gist options
  • Save ajesler/1bb951c07483f32ea3c395ccc9d0227b to your computer and use it in GitHub Desktop.
Save ajesler/1bb951c07483f32ea3c395ccc9d0227b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
# Appends an allow CORS header for files served from a dir.
# Useful when you have an html page that makes requests to load json files from the same dir.
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
BaseHTTPServer.test(CORSRequestHandler, BaseHTTPServer.HTTPServer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment