How do I get flask-cor to return Access-Control-Allow-Origin on Google App Engine?
Question: My python app does not throw any errors on Google App Engine, but the Allow-
Control-Access-Origin header is never sent. How can I ensure that I am sending
it with flask-cors?

    
    
    import MySQLdb
    import os
    import webapp2
    import json
    import flask
    from flask import Flask, jsonify, render_template, request
    from flask.ext.cors import CORS, cross_origin
    
    app = Flask(__name__)
    
    @app.route('/')
    @cross_origin()    
    def do_search():
      if (os.getenv('SERVER_SOFTWARE') and
        os.getenv('SERVER_SOFTWARE').startswith('Google App Engine/')):
        db = MySQLdb.connect(unix_socket='/cloudsql/my-instance-name:storeaddressdb', db='store_locator', user='myuser', passwd='password')
      else:
        db = MySQLdb.connect(host='localhost', user='root')
    
      cursor = db.cursor()
    
      query = 'SELECT * FROM stores WHERE 1 LIMIT 5'
      cursor.execute(query)
      resp = jsonify(data=cursor.fetchall())
      return resp
    
      db.close()
    


Answer: It appears that this code actually does work, although I do not see the Allow-
Control-Access-Origin header when I use cURL to test the url. The logs in
Google App Engine show CORS selectively adding the header unless the client
specifically skipped it. Also, the Javascript client is no longer showing an
error, and receives the data. It may not be the prettiest python code, but it
is functionally correct for my purposes.

