CORS Header Generator
Generate the correct Access-Control headers for your API with a visual builder.
Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, POST, PUT, DELETE Access-Control-Allow-Headers: Content-Type, Authorization Access-Control-Max-Age: 86400
Frequently Asked Questions
Code Implementation
# Flask β cors with flask-cors
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
# Allow specific origin
CORS(app, resources={r"/api/*": {
"origins": "https://example.com",
"methods": ["GET", "POST", "PUT", "DELETE"],
"allow_headers": ["Content-Type", "Authorization"],
"supports_credentials": True,
"max_age": 86400
}})
# Manual CORS headers in a response
from flask import make_response
@app.after_request
def add_cors_headers(response):
response.headers["Access-Control-Allow-Origin"] = "https://example.com"
response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
response.headers["Access-Control-Allow-Headers"] = "Content-Type, Authorization"
return responseComments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.