Advertisement
cardel

Test Flask

Nov 28th, 2024 (edited)
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from flask import Flask, jsonify, request, abort
  2. from flask_cors import CORS
  3.  
  4. app = Flask(__name__)
  5.  
  6. # Configurar CORS permitiendo solo dominios específicos
  7. CORS(app, origins=["http://www.example.com", "http://www.exampleB.com"], supports_credentials=True)
  8.  
  9. # Middleware para verificar los orígenes
  10. @app.before_request
  11. def check_origin():
  12.     allowed_origins = ["http://www.example.com", "http://www.exampleB.com"]
  13.     origin = request.headers.get("Origin")
  14.     if origin not in allowed_origins:
  15.         abort(403)  # Prohibido
  16.  
  17. @app.route("/")
  18. def home():
  19.     return jsonify({"message": "Bienvenido a la aplicación Flask con CORS configurado"}), 200
  20.  
  21. if __name__ == "__main__":
  22.     app.run(debug=True)
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement