|
1 | | -from contextlib import asynccontextmanager |
2 | | - |
3 | | -from fastapi import FastAPI, Request |
4 | | -from fastapi.middleware.cors import CORSMiddleware |
| 1 | +from mosayic import app |
| 2 | +from fastapi.responses import HTMLResponse |
5 | 3 |
|
6 | 4 | from app.core.settings import get_settings |
7 | 5 | from app.services.logger import get_logger |
8 | | -# from mosayic.core.firebase import initialize_firebase |
9 | 6 |
|
10 | 7 | logger = get_logger(__name__) |
11 | 8 | settings = get_settings() |
12 | | -DEBUG_MODE = settings.debug_mode |
13 | | - |
14 | | - |
15 | | -@asynccontextmanager |
16 | | -async def lifespan(app: FastAPI): |
17 | | - # initialize_firebase() |
18 | | - logger.info("Application startup: Initializing services...") |
19 | | - yield |
20 | | - |
21 | | - |
22 | | -# Set up FastAPI app - docs will be disabled dynamically in production |
23 | | -app = FastAPI( |
24 | | - title="Mosaygent API", |
25 | | - lifespan=lifespan, |
26 | | - generate_unique_id_function=lambda route: route.name, |
27 | | - docs_url=None if settings.environment == "production" else "/docs", |
28 | | - redoc_url=None if settings.environment == "production" else "/redoc", |
29 | | -) |
30 | | - |
31 | | - |
32 | | -# TODO: Set explicit CORS origins |
33 | | -app.add_middleware( |
34 | | - CORSMiddleware, |
35 | | - allow_origins=["*"], |
36 | | - allow_credentials=True, |
37 | | - allow_methods=["*"], |
38 | | - allow_headers=["*"], |
39 | | -) |
40 | 9 |
|
41 | 10 |
|
42 | | -@app.middleware("http") |
43 | | -async def add_charset_to_json_response(request: Request, call_next): |
| 11 | +@app.get("/", response_class=HTMLResponse) |
| 12 | +async def root(): |
| 13 | + html_content = """ |
| 14 | + <html> |
| 15 | + <body> |
| 16 | + <h1>The Python API</h1> |
| 17 | + <p>This is the API root. If you're in the development environment, visit <a href="/docs">/docs</a> to see the available |
| 18 | + endpoints.</p> |
| 19 | + </body> |
| 20 | + </html> |
44 | 21 | """ |
45 | | - This middleware ensures that all JSON responses have the 'charset=utf-8' |
46 | | - in their 'Content-Type' header. This is crucial for clients that do not |
47 | | - default to UTF-8, preventing character encoding issues. |
48 | | - """ |
49 | | - response = await call_next(request) |
50 | | - if "application/json" in response.headers.get( |
51 | | - "content-type", "" |
52 | | - ) and "charset" not in response.headers.get("content-type", ""): |
53 | | - response.headers["content-type"] = "application/json; charset=utf-8" |
54 | | - return response |
55 | | - |
56 | | - |
57 | | -# Include routers |
58 | | -# app.include_router(caloratio_router, prefix="/caloratio", tags=["Caloratio"]) |
59 | | - |
60 | | - |
61 | | -@app.get("/") |
62 | | -def read_root(): |
63 | | - return { |
64 | | - "message": "Welcome to the Mosaygent API", |
65 | | - "debug_mode": DEBUG_MODE, |
66 | | - "environment": settings.environment |
67 | | - } |
68 | | - |
69 | | - |
70 | | -@app.get("/health") |
71 | | -def health_check(): |
72 | | - return { |
73 | | - "status": "healthy", |
74 | | - "service": "mosaygent", |
75 | | - "debug": DEBUG_MODE, |
76 | | - "environment": settings.environment |
77 | | - } |
| 22 | + return HTMLResponse(content=html_content, status_code=200) |
0 commit comments