Skip to content

Instantly share code, notes, and snippets.

@chrahunt
Created February 7, 2015 17:36
Show Gist options
  • Save chrahunt/448c68b80c02748f2b85 to your computer and use it in GitHub Desktop.
Save chrahunt/448c68b80c02748f2b85 to your computer and use it in GitHub Desktop.
Serve content from a local file directory using Python 3.4 and include the 'Access-Control-Allow-Origin' header.
#! /usr/bin/env python2
# From http://stackoverflow.com/a/21957017/1698058
from http.server import SimpleHTTPRequestHandler, HTTPServer
import http.server
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
if __name__ == '__main__':
http.server.test(CORSRequestHandler, HTTPServer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment