|
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") |
|
|
|
|
|
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) |
|
|