alexisrolland / flask-graphene-sqlalchemy

⚗️Project template to build a GraphQL API in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to enable cors

congjinruo opened this issue · comments

commented

before use flask_graphql:
@app.route('/api/currentUser/')
def currentUser():
jsonStr = '{"name":"XXX","avatar":"XXX","userid":"00000001","notifyCount":12}'
res = flask.Response(jsonStr)
res.headers['Access-Control-Allow-Method'] = 'GET,POST,OPTIONS,DELETE,PUT'
res.headers['Access-Control-Allow-Origin'] = '*'
return res

after user flask_graphql:
app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql = True, context={'session': db_session}))
And I do not know how to enable CORS

commented

OK , I find this: Flask-CORS