diff --git a/app/main.py b/app/main.py index d7eefed..3656678 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,9 @@ import logging +from pathlib import Path from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import HTMLResponse from app.admin.router import router as admin_router from app.applicants.router import router as applicants_router @@ -33,6 +35,35 @@ Base.metadata.create_all(bind=engine) logger.info("Database tables created") +# Cache for landing page template +_landing_page_template: str = "" + + +@app.on_event("startup") +async def startup_event(): + """Validate application configuration and load required resources.""" + global _landing_page_template + + # Load landing page template - fail fast if not available + html_path = Path(__file__).parent / "templates" / "index.html" + try: + _landing_page_template = html_path.read_text() + logger.info("Landing page template loaded successfully from %s", html_path) + except FileNotFoundError as exc: + logger.critical("Landing page template not found at %s", html_path) + raise RuntimeError(f"Required template file not found: {html_path}") from exc + except Exception as e: + logger.critical("Failed to load landing page template: %s", e) + raise RuntimeError(f"Failed to load required template: {e}") from e + + +# Root endpoint with API documentation links +@app.get("/", response_class=HTMLResponse, include_in_schema=False) +def root(): + """Render an HTML page with links to API documentation.""" + return _landing_page_template + + # Add routes app.include_router(cases_router) app.include_router(applicants_router) diff --git a/app/templates/index.html b/app/templates/index.html new file mode 100644 index 0000000..a492578 --- /dev/null +++ b/app/templates/index.html @@ -0,0 +1,76 @@ + + + + + + Comet API + + + + +
+

🚀 Welcome to the Comet API!

+

Choose your preferred documentation format:

+ +
+ +