diff --git a/backend/app.py b/backend/app.py index 4b6e14b1..a4cc0031 100644 --- a/backend/app.py +++ b/backend/app.py @@ -10,7 +10,7 @@ from src import config app = FastAPI() -origins = ["https://localhost:5173"] +origins = [config.CONFIG.frontend_url] app.add_middleware( CORSMiddleware, allow_origins=origins, @@ -48,8 +48,7 @@ async def profile(request: Request): def login(request: Request, next: Optional[str] = None, ticket: Optional[str] = None): if request.session.get("user", None): # Already logged in - # TODO: dit is hardcoded, moet nog op een of andere manier aangepast worden - return RedirectResponse("https://localhost:5173/home") + return RedirectResponse(f"{config.CONFIG.frontend_url}/home") if not ticket: # No ticket, the request come from end user, send to CAS login @@ -77,8 +76,7 @@ def login(request: Request, next: Optional[str] = None, ticket: Optional[str] = if not next: return # response = RedirectResponse(next) - # TODO: dit is hardcoded, moet nog op een of andere manier aangepast worden - response = RedirectResponse("https://localhost:5173/home") + response = RedirectResponse(f"{config.CONFIG.frontend_url}/home") request.session["user"] = dict(user=user) return response diff --git a/backend/config.yml b/backend/config.yml index b3e5e70b..0b441e36 100644 --- a/backend/config.yml +++ b/backend/config.yml @@ -1,2 +1,3 @@ api_url: https://localhost:8080 +frontend_url: https://localhost:5173 cas_server_url: https://login.ugent.be diff --git a/backend/src/config.py b/backend/src/config.py index 0ce7a344..e3014ecd 100644 --- a/backend/src/config.py +++ b/backend/src/config.py @@ -9,13 +9,15 @@ @dataclass class Config: api_url: str = "http://localhost:8000" - cas_server_url: str = "http://localhost:8001" + frontend_url: str = "http://localhost:8001" + cas_server_url: str = "http://localhost:8002" def read(self, config_file) -> Config: with open(config_file, "r") as file: user_config = yaml.safe_load(file) for field in dataclasses.fields(Config): - user_value = user_config.get(field.name, getattr(self, field.name)) + user_value = user_config.get( + field.name, getattr(self, field.name)) setattr(self, field.name, user_value) return self