Skip to content

Commit ceea7a7

Browse files
authored
Merge pull request #19 from MetroStar/root-landing
Add Root Landing Page
2 parents 8773b3a + f3ac8e6 commit ceea7a7

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

app/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import logging
2+
from pathlib import Path
23

34
from fastapi import FastAPI
45
from fastapi.middleware.cors import CORSMiddleware
6+
from fastapi.responses import HTMLResponse
57

68
from app.admin.router import router as admin_router
79
from app.applicants.router import router as applicants_router
@@ -33,6 +35,35 @@
3335
Base.metadata.create_all(bind=engine)
3436
logger.info("Database tables created")
3537

38+
# Cache for landing page template
39+
_landing_page_template: str = ""
40+
41+
42+
@app.on_event("startup")
43+
async def startup_event():
44+
"""Validate application configuration and load required resources."""
45+
global _landing_page_template
46+
47+
# Load landing page template - fail fast if not available
48+
html_path = Path(__file__).parent / "templates" / "index.html"
49+
try:
50+
_landing_page_template = html_path.read_text()
51+
logger.info("Landing page template loaded successfully from %s", html_path)
52+
except FileNotFoundError as exc:
53+
logger.critical("Landing page template not found at %s", html_path)
54+
raise RuntimeError(f"Required template file not found: {html_path}") from exc
55+
except Exception as e:
56+
logger.critical("Failed to load landing page template: %s", e)
57+
raise RuntimeError(f"Failed to load required template: {e}") from e
58+
59+
60+
# Root endpoint with API documentation links
61+
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
62+
def root():
63+
"""Render an HTML page with links to API documentation."""
64+
return _landing_page_template
65+
66+
3667
# Add routes
3768
app.include_router(cases_router)
3869
app.include_router(applicants_router)

app/templates/index.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Comet API</title>
7+
<link
8+
rel="icon"
9+
type="image/png"
10+
href="https://fastapi.tiangolo.com/img/favicon.png"
11+
/>
12+
<style>
13+
body {
14+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
15+
Oxygen, Ubuntu, Cantarell, sans-serif;
16+
display: flex;
17+
justify-content: center;
18+
align-items: center;
19+
min-height: 100vh;
20+
margin: 0;
21+
background: #0f1419;
22+
}
23+
.container {
24+
background: rgba(30, 41, 51, 0.8);
25+
border: 1px solid rgba(255, 255, 255, 0.1);
26+
padding: 2rem 4rem 4rem 4rem;
27+
border-radius: 10px;
28+
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
29+
text-align: center;
30+
max-width: 600px;
31+
width: 90%;
32+
}
33+
h1 {
34+
color: #ffffff;
35+
margin-bottom: 0.5rem;
36+
font-weight: 600;
37+
font-size: 2rem;
38+
}
39+
p {
40+
color: #b8c5d0;
41+
margin-bottom: 2rem;
42+
line-height: 1.6;
43+
}
44+
.links {
45+
display: flex;
46+
flex-direction: column;
47+
gap: 1rem;
48+
}
49+
a {
50+
display: block;
51+
padding: 1rem 2rem;
52+
background: #6ee7b7;
53+
color: #0f1419;
54+
text-decoration: none;
55+
border-radius: 5px;
56+
font-weight: 600;
57+
transition: all 0.3s ease;
58+
}
59+
a:hover {
60+
background: #5cd3a3;
61+
transform: translateY(-2px);
62+
box-shadow: 0 5px 15px rgba(110, 231, 183, 0.4);
63+
}
64+
</style>
65+
</head>
66+
<body>
67+
<div class="container">
68+
<h1>🚀 Welcome to the Comet API!</h1>
69+
<p>Choose your preferred documentation format:</p>
70+
<div class="links">
71+
<a href="/docs">📘 Swagger UI</a>
72+
<a href="/redoc">📗 ReDoc</a>
73+
</div>
74+
</div>
75+
</body>
76+
</html>

0 commit comments

Comments
 (0)