From 935387514bb91efa4f983393e9c938f7548424d3 Mon Sep 17 00:00:00 2001 From: Rendy Arya Kemal Date: Wed, 19 Jun 2024 20:05:46 +0700 Subject: [PATCH] fix: add conditional root path --- .github/workflows/deployment.yml | 2 +- cefies/app.py | 7 ++++++- cefies/security.py | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml index d6991de..d029e2b 100644 --- a/.github/workflows/deployment.yml +++ b/.github/workflows/deployment.yml @@ -47,4 +47,4 @@ jobs: gcloud auth configure-docker ${{ vars.REGION }}-docker.pkg.dev --quiet docker container rm -f chefies-backend docker image rm -f ${{ vars.GAR_LOCATION }}/backend - docker run --name chefies-backend -e GOOGLE_APPLICATION_CREDENTIALS="/app/keys/credentials.json" -d --restart always -p 9000:80 ${{ vars.GAR_LOCATION }}/backend + docker run --name chefies-backend -e PRODUCTION=1 -e GOOGLE_APPLICATION_CREDENTIALS="/app/keys/credentials.json" -d --restart always -p 9000:80 ${{ vars.GAR_LOCATION }}/backend diff --git a/cefies/app.py b/cefies/app.py index caa8925..8480455 100644 --- a/cefies/app.py +++ b/cefies/app.py @@ -1,3 +1,4 @@ +import os from fastapi import FastAPI from dotenv import load_dotenv @@ -6,7 +7,11 @@ import cefies.internal.firestore # noqa: F401 -- Intended to initialize Firebase from cefies.routes import index_router, auth_router, profile_router -app = FastAPI(root_path="/api") +root_path = "" +if os.getenv("PRODUCTION"): + root_path = "/api" + +app = FastAPI(root_path=root_path) app.include_router(index_router) app.include_router(auth_router) app.include_router(profile_router) diff --git a/cefies/security.py b/cefies/security.py index 97b26f1..450b4b2 100644 --- a/cefies/security.py +++ b/cefies/security.py @@ -13,7 +13,11 @@ ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30 -security = OAuth2PasswordBearer("/auth/login") +login_path = "/auth/login" +if os.getenv("PRODUCTION"): + login_path = "/api" + login_path + +security = OAuth2PasswordBearer(login_path) def authenticate_user(email: str, password: str):