Created
May 23, 2012 17:41
-
-
Save julescarbon/2776598 to your computer and use it in GitHub Desktop.
view-serving main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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