from flask import jsonifydef test_cors_json(request): if request.method == 'OPTIONS': headers = { # 'Access-Control-Allow-Origin': 'https://mydomain.com', 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET, POST, OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization', 'Access-Control-Max-Age': '3600' # 'Access-Control-Allow-Credentials': 'true' } return ('', 204, headers) ''' headers = { 'Access-Control-Allow-Origin': 'https://mydomain.com', 'Access-Control-Allow-Credentials': 'true' } return ('Hello World!', 200, headers) ''' data = { 'name': 'Test CORS OK' } response = jsonify({ 'data': data }) response.headers.set('Access-Control-Allow-Origin', '*') return response
References: