Last active
August 29, 2015 13:56
-
-
Save skaiser/9103793 to your computer and use it in GitHub Desktop.
(Very) Simple AppEngine python XHR proxy
This file contains 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
application: <YOUR_APPSPOT.COM_NAME> | |
version: 1 | |
runtime: python27 | |
api_version: 1 | |
threadsafe: yes | |
default_expiration: "30d" | |
handlers: | |
- url: /_xhr | |
script: xhr_proxy.app | |
- url: /static | |
static_dir: static | |
# site root | |
- url: / | |
static_files: static/index.html | |
upload: static/index.html | |
expiration: "15m" |
This file contains 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
# Modified from: https://w00kie.com/2008/06/18/crossdomain-proxy-on-google-app-engine/ | |
# | |
# Usage w/ jQuery: | |
# $.ajax({ | |
# type: 'GET', | |
# url: '/_xhr', | |
# data: { | |
# url: 'https://plus.google.com/108057472278845204990' | |
# }, | |
# success: function (resp) { | |
# console.log($(resp).find('img[alt="Cover photo"]')); | |
# } | |
# }); | |
import cgi | |
import webapp2 | |
from google.appengine.api import urlfetch | |
class XHR(webapp2.RequestHandler): | |
def get(self): | |
url = self.request.get('url') | |
if url: | |
result = urlfetch.fetch(url=url, method=urlfetch.GET) | |
self.response.out.write(result.content) | |
app = webapp2.WSGIApplication([('/_xhr', XHR)], | |
debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment