Skip to content

Instantly share code, notes, and snippets.

@skaiser
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaiser/9103793 to your computer and use it in GitHub Desktop.
Save skaiser/9103793 to your computer and use it in GitHub Desktop.
(Very) Simple AppEngine python XHR proxy
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"
# 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