Update app.py

This commit is contained in:
2026-04-19 20:24:07 +00:00
parent 7ead16f35a
commit 7dba33883e

20
app.py
View File

@@ -1,11 +1,27 @@
from flask import Flask from flask import Flask, request, jsonify
from flask_cors import CORS from flask_cors import CORS
from db import init_db from db import init_db
from routes.api import api from routes.api import api
from routes.dashboard import dashboard from routes.dashboard import dashboard
app = Flask(__name__) app = Flask(__name__)
CORS(app) # Allow cross-origin requests from the Tampermonkey script
CORS(app, resources={r"/*": {"origins": "*"}}, supports_credentials=False)
# Belt-and-suspenders: inject CORS headers on every response,
# including error responses that flask-cors might miss.
@app.after_request
def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, DELETE, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type, Authorization'
return response
# Explicitly handle OPTIONS preflight for all routes
@app.route('/', defaults={'path': ''}, methods=['OPTIONS'])
@app.route('/<path:path>', methods=['OPTIONS'])
def handle_options(path):
return jsonify({}), 200
app.register_blueprint(api) app.register_blueprint(api)
app.register_blueprint(dashboard) app.register_blueprint(dashboard)