|
4 | 4 |
|
5 | 5 | from litestar import Litestar, get |
6 | 6 | from litestar.config.cors import CORSConfig |
7 | | -from litestar.contrib.jinja import JinjaTemplateEngine |
8 | 7 | from litestar.openapi.config import OpenAPIConfig |
9 | 8 | from litestar.openapi.plugins import SwaggerRenderPlugin |
10 | | -from litestar.response import Template |
| 9 | +from litestar.response import Redirect |
11 | 10 | from litestar.static_files import create_static_files_router |
12 | | -from litestar.template.config import TemplateConfig |
13 | 11 |
|
14 | 12 | from .db import close_pool, ensure_schema, open_pool |
15 | 13 | from .queries import fetch_state |
16 | 14 | from .routers.hashtag import v2_router |
17 | 15 | from .schemas import HealthResponse |
18 | 16 |
|
19 | | -TEMPLATES = Path(__file__).parent / "templates" |
20 | 17 | FRONTEND_DIST = os.getenv("FRONTEND_DIST") |
21 | 18 | DEFAULT_CORS_ORIGINS = ( |
22 | 19 | "http://localhost:5173", |
@@ -48,13 +45,14 @@ async def lifespan(app: Litestar): |
48 | 45 |
|
49 | 46 |
|
50 | 47 | @get("/", include_in_schema=False) |
51 | | -async def home() -> Template: |
52 | | - return Template("home.html") |
| 48 | +async def home() -> Redirect: |
| 49 | + return Redirect(path="/docs") |
53 | 50 |
|
54 | 51 |
|
55 | 52 | def _root_handlers() -> list: |
56 | | - """Serve the built frontend at / when FRONTEND_DIST is a directory, else the API home page. Explicit API |
57 | | - routes (/health, /api/*, /docs) take precedence over the static catch-all; html_mode serves index.html.""" |
| 53 | + """Serve the built frontend at / when FRONTEND_DIST is a directory, else redirect to the API docs. |
| 54 | + Explicit API routes (/health, /api/*, /docs) take precedence over the static catch-all; html_mode |
| 55 | + serves index.html.""" |
58 | 56 | if FRONTEND_DIST and Path(FRONTEND_DIST).is_dir(): |
59 | 57 | return [create_static_files_router(path="/", directories=[FRONTEND_DIST], html_mode=True)] |
60 | 58 | return [home] |
@@ -88,5 +86,4 @@ async def health() -> HealthResponse: |
88 | 86 | path="/docs", |
89 | 87 | render_plugins=[SwaggerRenderPlugin()], |
90 | 88 | ), |
91 | | - template_config=TemplateConfig(directory=TEMPLATES, engine=JinjaTemplateEngine), # ty: ignore[invalid-argument-type] |
92 | 89 | ) |
0 commit comments