removed fastapi dep and added requirements

This commit is contained in:
edwin
2026-02-03 22:29:43 -08:00
parent f886745135
commit 552223cc6d
2 changed files with 35 additions and 20 deletions

View File

@@ -2,6 +2,7 @@ from fastapi import FastAPI, APIRouter
from dotenv import load_dotenv
from starlette.middleware.cors import CORSMiddleware
from motor.motor_asyncio import AsyncIOMotorClient
from contextlib import asynccontextmanager
import os
import logging
from pathlib import Path
@@ -19,13 +20,6 @@ mongo_url = os.environ['MONGO_URL']
client = AsyncIOMotorClient(mongo_url)
db = client[os.environ['DB_NAME']]
# Create the main app without a prefix
app = FastAPI()
# Create a router with the /api prefix
api_router = APIRouter(prefix="/api")
# Define Models
class StatusCheck(BaseModel):
model_config = ConfigDict(extra="ignore") # Ignore MongoDB's _id field
@@ -37,6 +31,16 @@ class StatusCheck(BaseModel):
class StatusCheckCreate(BaseModel):
client_name: str
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Create a router with the /api prefix
api_router = APIRouter(prefix="/api")
# Add your routes to the router instead of directly to app
@api_router.get("/")
async def root():
@@ -66,6 +70,19 @@ async def get_status_checks():
return status_checks
# Define lifespan event handler
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup code here
logger.info("Application startup")
yield
# Shutdown code here
logger.info("Application shutdown")
client.close()
# Create the main app with lifespan handler
app = FastAPI(lifespan=lifespan)
# Include the router in the main app
app.include_router(api_router)
@@ -76,15 +93,3 @@ app.add_middleware(
allow_methods=["*"],
allow_headers=["*"],
)
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
@app.on_event("shutdown")
async def shutdown_db_client():
client.close()

10
app/requirements.txt Normal file
View File

@@ -0,0 +1,10 @@
fastapi
dotenv
starlette
motor
#os
logging
pathlib
pydantic
typing
datetime