From dcf133a8e55136a5256426b141130021fe502ec2 Mon Sep 17 00:00:00 2001 From: Olwe Samuel Date: Tue, 3 Dec 2024 14:04:42 +0300 Subject: [PATCH] Added CORS library --- requirements.txt | 3 ++- webapp/__init__.py | 4 ++++ webapp/sso.py | 6 ------ 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2640fcff..a90e853b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ django-openid-auth==0.17 -Flask-OpenID==1.3.1 +Flask-Cors==5.0.0 Flask-Migrate==4.0.7 +Flask-OpenID==1.3.1 Flask-Pydantic==0.12.0 Flask-SQLAlchemy==3.1.1 gunicorn[gevent]==23.0.0 diff --git a/webapp/__init__.py b/webapp/__init__.py index 94e71564..f7562fcb 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -2,6 +2,7 @@ import os import flask +from flask_cors import CORS from werkzeug.debug import DebuggedApplication from werkzeug.middleware.proxy_fix import ProxyFix @@ -24,6 +25,9 @@ def create_app(): app.config.from_pyfile("settings.py") app.context_processor(base_context) + # Add CORS headers + CORS(app, origins=["login.ubuntu.com"]) + # Initialize database init_db(app) diff --git a/webapp/sso.py b/webapp/sso.py index 9c6a0d23..0b46b2d4 100644 --- a/webapp/sso.py +++ b/webapp/sso.py @@ -47,12 +47,6 @@ def logout(): return flask.redirect("/login") - # Allow CORS - @app.after_request - def after_request_func(response): - response.headers["Access-Control-Allow-Origin"] = SSO_LOGIN_URL - return response - def login_required(func): """