Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, jsonify, request, abort
- from flask_cors import CORS
- app = Flask(__name__)
- # Configurar CORS permitiendo solo dominios específicos
- CORS(app, origins=["http://www.example.com", "http://www.exampleB.com"], supports_credentials=True)
- # Middleware para verificar los orígenes
- @app.before_request
- def check_origin():
- allowed_origins = ["http://www.example.com", "http://www.exampleB.com"]
- origin = request.headers.get("Origin")
- if origin not in allowed_origins:
- abort(403) # Prohibido
- @app.route("/")
- def home():
- return jsonify({"message": "Bienvenido a la aplicación Flask con CORS configurado"}), 200
- if __name__ == "__main__":
- app.run(debug=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement