Skip to content

Commit

Permalink
chore: move home page route to routers module
Browse files Browse the repository at this point in the history
  • Loading branch information
M03ED committed Sep 4, 2024
1 parent f0a7e21 commit d87fee5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
11 changes: 4 additions & 7 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from fastapi.routing import APIRoute
from fastapi_responses import custom_openapi

from config import DOCS, XRAY_SUBSCRIPTION_PATH, HOME_PAGE_TEMPLATE, ALLOWED_ORIGINS
from config import DOCS, XRAY_SUBSCRIPTION_PATH, ALLOWED_ORIGINS

__version__ = "0.6.0"

Expand All @@ -34,17 +34,19 @@

from app import dashboard, telegram, routers, jobs # noqa
from app.routers import api_router
from app.templates import render_template

app.include_router(api_router)


def use_route_names_as_operation_ids(app: FastAPI) -> None:
for route in app.routes:
if isinstance(route, APIRoute):
route.operation_id = route.name


use_route_names_as_operation_ids(app)


@app.on_event("startup")
def on_startup():
paths = [f"{r.path}/" for r in app.routes]
Expand All @@ -68,8 +70,3 @@ def validation_exception_handler(request: Request, exc: RequestValidationError):
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
content=jsonable_encoder({"detail": details}),
)


@app.get("/", response_class=HTMLResponse)
def base():
return render_template(HOME_PAGE_TEMPLATE)
4 changes: 3 additions & 1 deletion app/routers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
subscription,
system,
user_template,
user
user,
home,
)

api_router = APIRouter()
Expand All @@ -19,6 +20,7 @@
system.router,
user_template.router,
user.router,
home.router,
]

for router in routers:
Expand Down
12 changes: 12 additions & 0 deletions app/routers/home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from fastapi import APIRouter
from fastapi.responses import HTMLResponse

from config import HOME_PAGE_TEMPLATE
from app.templates import render_template

router = APIRouter()


@router.get("/", response_class=HTMLResponse)
def base():
return render_template(HOME_PAGE_TEMPLATE)

0 comments on commit d87fee5

Please sign in to comment.