Skip to content

Commit

Permalink
add frontend_url to config
Browse files Browse the repository at this point in the history
  • Loading branch information
reyniersbram committed Mar 2, 2024
1 parent f3da328 commit 46fa0b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 3 additions & 5 deletions backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions backend/config.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
api_url: https://localhost:8080
frontend_url: https://localhost:5173
cas_server_url: https://login.ugent.be
6 changes: 4 additions & 2 deletions backend/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 46fa0b1

Please sign in to comment.