Question 18
Consider the below CORS enabled flask app.
from flask import Flaskfrom flask_cors import CORS
app = Flask(__name__)CORS(app, resources={r"/api/*": {"origins": "http://localhost:5000"}})
@app.route("/api/data")def data(): return {"message": "Hello from Flask"}If a Vue.js frontend (simulation given below) at “http://localhost:3000” tries to fetch data, what will happen?
fetch("http://localhost:5000/api/data") .then(response => response.json()) .then(data => console.log(data));The request will be blocked due to CORS policy.
The request will succeed and return { "message": "Hello from Flask" }.
The request will fail because Vue.js does not support CORS.
The server will crash due to incorrect CORS settings.