Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
76 changes: 76 additions & 0 deletions app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Comet API</title>
<link
rel="icon"
type="image/png"
href="https://fastapi.tiangolo.com/img/favicon.png"
/>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
Oxygen, Ubuntu, Cantarell, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background: #0f1419;
}
.container {
background: rgba(30, 41, 51, 0.8);
border: 1px solid rgba(255, 255, 255, 0.1);
padding: 2rem 4rem 4rem 4rem;
border-radius: 10px;
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
text-align: center;
max-width: 600px;
width: 90%;
}
h1 {
color: #ffffff;
margin-bottom: 0.5rem;
font-weight: 600;
font-size: 2rem;
}
p {
color: #b8c5d0;
margin-bottom: 2rem;
line-height: 1.6;
}
.links {
display: flex;
flex-direction: column;
gap: 1rem;
}
a {
display: block;
padding: 1rem 2rem;
background: #6ee7b7;
color: #0f1419;
text-decoration: none;
border-radius: 5px;
font-weight: 600;
transition: all 0.3s ease;
}
a:hover {
background: #5cd3a3;
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(110, 231, 183, 0.4);
}
</style>
</head>
<body>
<div class="container">
<h1>🚀 Welcome to the Comet API!</h1>
<p>Choose your preferred documentation format:</p>
<div class="links">
<a href="/docs">📘 Swagger UI</a>
<a href="/redoc">📗 ReDoc</a>
</div>
</div>
</body>
</html>