Coverage for src/kwai/frontend/apps/_auth.py: 0%
20 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines the routes for the authentication frontend application."""
3from pathlib import Path
4from typing import Annotated
6from fastapi import APIRouter, Depends, Request
7from fastapi.templating import Jinja2Templates
9from kwai.api.dependencies import create_templates
10from kwai.frontend.dependencies import ViteDependency
11from kwai.frontend.etag_file_response import EtagFileResponse
12from kwai.frontend.vite import Vite
15APP_NAME = "auth"
17router = APIRouter(prefix=f"/{APP_NAME}")
19_auth_vite_dependency = ViteDependency(APP_NAME)
22@router.get("/{path:path}", name=APP_NAME)
23async def get_app(
24 path: Path,
25 request: Request,
26 templates: Annotated[Jinja2Templates, Depends(create_templates)],
27 vite: Annotated[Vite, Depends(_auth_vite_dependency)],
28):
29 asset_file_path = vite.get_asset_path(path)
30 if asset_file_path is not None:
31 return EtagFileResponse(asset_file_path)
33 url = request.url_for(APP_NAME, path="")
34 if "x-forwarded-proto" in request.headers:
35 url = url.replace(scheme=request.headers["x-forwarded-proto"])
37 return templates.TemplateResponse(
38 request,
39 name="index.jinja2",
40 context={
41 "application": {
42 "name": APP_NAME,
43 "url": str(url),
44 },
45 "vite": vite,
46 },
47 )