-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathapp.py
More file actions
35 lines (22 loc) · 962 Bytes
/
app.py
File metadata and controls
35 lines (22 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from routes.posts import PostRouter
from routes.users import UserRouter
from fastapi import FastAPI
from database.database import engine
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
print("🚀 App starting...")
# ✅ Properly open a connection context
async with engine.begin() as conn:
# optional: run startup scripts (like create_all)
pass
yield # App is running
print("🧹 App shutting down...")
await engine.dispose()
print("✅ App shutdown complete.")
app = FastAPI(lifespan=lifespan, description="Template for building FastAPI applications with PostgreSQL", contact={"email": "samanidarix@gmail.com"})
@app.get("/", tags=["Root"])
async def read_root():
return {"message": "Welcome to this fantastic app."}
app.include_router(UserRouter, tags=["USERS"], prefix="/users")
app.include_router(PostRouter, tags=["Posts"], prefix="/posts",)