Skip to content

Instantly share code, notes, and snippets.

@luigi
Created July 19, 2017 13:40
Show Gist options
  • Save luigi/b876049ed5d96769bca1df3381373058 to your computer and use it in GitHub Desktop.
Save luigi/b876049ed5d96769bca1df3381373058 to your computer and use it in GitHub Desktop.
Python SimpleHTTPServer for AMP

A small Python webserver for serving AMP files locally in development. Adds the required headers for CORS requests.

Run the server.py script from the directory you wish to act as the root of your webserver:

$ python server.py

#!/usr/bin/env python
import SimpleHTTPServer
class AMPHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Access-Control-Allow-Origin", "http://localhost:8000")
self.send_header("AMP-Access-Control-Allow-Source-Origin", "http://localhost:8000")
self.send_header("Access-Control-Expose-Headers", "AMP-Access-Control-Allow-Source-Origin")
if __name__ == '__main__':
SimpleHTTPServer.test(HandlerClass=AMPHandler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment