Skip to content

Instantly share code, notes, and snippets.

@julescarbon
Created May 23, 2012 17:41
Show Gist options
  • Save julescarbon/2776598 to your computer and use it in GitHub Desktop.
Save julescarbon/2776598 to your computer and use it in GitHub Desktop.
view-serving main.py
#!/usr/bin/env python
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
import urllib2
import os
class MainHandler (webapp.RequestHandler):
def get (self):
# Set the cross origin resource sharing header to allow AJAX
self.response.headers.add_header ("Access-Control-Allow-Origin", "*")
# Proxy local files so CORS works -- note! does not work for files in static/
path = self.request.get('path')
if path and os.path.exists('views/' + path) and path.find(".html") != -1:
result = open ('views/' + path)
self.response.out.write (result.read())
else:
self.response.out.write ('{"message":"Hello World!"}\n')
def main ():
application = webapp.WSGIApplication ([('/', MainHandler)], debug=True)
util.run_wsgi_app (application)
if __name__ == '__main__':
main ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment