File size: 778 Bytes
fade1d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware

from .routes.records import router as records_router
from .database.connection import connect_to_mongo, close_mongo_connection
from .services.record_service import RecordService
from .config.settings import ALLOWED_ORIGINS

app = FastAPI(title="Expense Tracker API", version="1.0.0")

# CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=ALLOWED_ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

@app.on_event("startup")
async def startup_event():
    await connect_to_mongo()
    await RecordService().ensure_indexes()

@app.on_event("shutdown")
async def shutdown_event():
    await close_mongo_connection()

app.include_router(records_router)