From 16df7e2cc7c5967e570803898c518e25757d811c Mon Sep 17 00:00:00 2001 From: Alix JEUDI--LEMOINE Date: Mon, 13 Jan 2025 16:03:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20Fix=20CORS=20issue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/main.py b/app/main.py index 1982dc7..a8c0fb4 100644 --- a/app/main.py +++ b/app/main.py @@ -1,5 +1,6 @@ import bson from fastapi import FastAPI, Depends, HTTPException, status +from fastapi.middleware.cors import CORSMiddleware from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm from datetime import datetime, timedelta from joserfc import jwt @@ -37,6 +38,21 @@ app = FastAPI( root_path_in_servers=False ) + +app = FastAPI() + +origins = [ + "*", # Allow all origins +] + +app.add_middleware( + CORSMiddleware, + allow_origins=origins, + allow_credentials=True, + allow_methods=["*"], + allow_headers=["*"], +) + # OAuth2 scheme oauth2_scheme = OAuth2PasswordBearer(tokenUrl=config.TOKEN_URL)