Skip to content

Commit 9403396

Browse files
authored
Merge pull request #22 from MetroStar/use-root-path
Use Root Path
2 parents 7b9bc53 + 0dcdddf commit 9403396

7 files changed

Lines changed: 16 additions & 17 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The goal of this project is to provide a Python-based starter API, which comes p
2929
To override default environment variables, add a `.env` file to the `comet-api` directory and update as needed (optional):
3030

3131
```
32-
API_PREFIX=[SOME_ROUTE] # Ex: '/api'
32+
ROOT_PATH=[SOME_ROUTE] # Ex: '/api'
3333
DATABASE_URL=[SOME_URL] # Ex: 'postgresql://username:password@localhost:5432/database_name'
3434
OIDC_CONFIG_URL=[SOME_URL] # Ex: 'https://keycloak.auth.metrostar.cloud/auth/realms/dev/.well-known/openid-configuration'
3535
LOG_LEVEL=[LOG_LEVEL] # Ex: 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL' (Default: 'INFO')

app/admin/router.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
from starlette import status
55

66
from app.auth import validate_jwt
7-
from app.config import settings
87

98
router = APIRouter(
10-
prefix=f"{settings.API_PREFIX}/admin",
9+
prefix="/admin",
1110
tags=["Admin"],
1211
)
1312

app/applicants/router.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
ApplicantResponse,
1212
ApplicantUpdate,
1313
)
14-
from app.config import settings
1514
from app.db import get_db
1615

1716
router = APIRouter(
18-
prefix=f"{settings.API_PREFIX}/applicants",
17+
prefix="/applicants",
1918
tags=["Applicants"],
2019
responses={404: {"description": "Endpoint not found"}},
2120
)
@@ -24,7 +23,7 @@
2423
db_session = Annotated[Session, Depends(get_db)]
2524

2625

27-
@router.get("/", status_code=status.HTTP_200_OK, response_model=ApplicantListResponse)
26+
@router.get("", status_code=status.HTTP_200_OK, response_model=ApplicantListResponse)
2827
async def get_applicants(db: db_session, page_number: int = 0, page_size: int = 100):
2928
"""Retrieve a paginated list of all applicants.
3029
@@ -39,7 +38,7 @@ async def get_applicants(db: db_session, page_number: int = 0, page_size: int =
3938
return service.get_items(db, page_number, page_size)
4039

4140

42-
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=ApplicantResponse)
41+
@router.post("", status_code=status.HTTP_201_CREATED, response_model=ApplicantResponse)
4342
async def create_applicant(applicant: ApplicantCreate, db: db_session):
4443
"""Create a new applicant.
4544

app/cases/router.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
CaseUpdate,
1313
CaseWithApplicant,
1414
)
15-
from app.config import settings
1615
from app.db import get_db
1716

1817
router = APIRouter(
19-
prefix=f"{settings.API_PREFIX}/cases",
18+
prefix="/cases",
2019
tags=["Cases"],
2120
responses={404: {"description": "Endpoint not found"}},
2221
)
@@ -25,7 +24,7 @@
2524
db_session = Annotated[Session, Depends(get_db)]
2625

2726

28-
@router.get("/", status_code=status.HTTP_200_OK, response_model=CaseListResponse)
27+
@router.get("", status_code=status.HTTP_200_OK, response_model=CaseListResponse)
2928
async def get_cases(db: db_session, page_number: int = 0, page_size: int = 100):
3029
"""Retrieve a paginated list of all cases.
3130
@@ -40,7 +39,7 @@ async def get_cases(db: db_session, page_number: int = 0, page_size: int = 100):
4039
return service.get_items(db, page_number, page_size)
4140

4241

43-
@router.post("/", status_code=status.HTTP_201_CREATED, response_model=CaseResponse)
42+
@router.post("", status_code=status.HTTP_201_CREATED, response_model=CaseResponse)
4443
async def create_case(case: CaseCreate, db: db_session):
4544
"""Create a new case.
4645

app/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Settings(BaseSettings):
1010

1111
model_config = SettingsConfigDict(env_file=".env")
1212

13-
API_PREFIX: str = ""
13+
ROOT_PATH: str = ""
1414
DATABASE_URL: str = "sqlite:///./db.sqlite3"
1515
OIDC_CONFIG_URL: str | None = None
1616
LOG_LEVEL: str = "INFO"

app/health/router.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from fastapi import APIRouter
22
from starlette import status
33

4-
from app.config import settings
5-
64
router = APIRouter(
7-
prefix=f"{settings.API_PREFIX}/health",
5+
prefix="/health",
86
tags=["Health"],
97
)
108

119

12-
@router.get("/", status_code=status.HTTP_200_OK)
10+
@router.get("", status_code=status.HTTP_200_OK)
1311
def get_health():
1412
"""Health check endpoint.
1513

app/main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from app.admin.router import router as admin_router
99
from app.applicants.router import router as applicants_router
1010
from app.cases.router import router as cases_router
11+
from app.config import settings
1112
from app.db import Base, engine
1213
from app.health.router import router as health_router
1314
from app.utils import setup_logging
@@ -16,8 +17,11 @@
1617
setup_logging()
1718
logger = logging.getLogger(__name__)
1819

20+
# Set root path if specified in settings
21+
root_path = settings.ROOT_PATH if settings.ROOT_PATH else ""
22+
1923
# Create the app
20-
app = FastAPI()
24+
app = FastAPI(root_path=root_path)
2125
logger.info("FastAPI application initialized")
2226

2327
# Set up CORS middleware

0 commit comments

Comments
 (0)