-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
55 lines (42 loc) · 1.5 KB
/
main.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi_sqlalchemy import DBSessionMiddleware
from starlette.middleware.cors import CORSMiddleware
from database import Database
from identity_reconciliation.controllers.contacts import router as contact_router
# Initialize FastAPI
app = FastAPI()
# Load environment variables
load_dotenv()
DB_USER = os.getenv("DB_USER")
DB_PASS = os.getenv("DB_PASS")
DB_HOST = os.getenv("DB_HOST")
DB_NAME = os.getenv("DB_NAME")
DB_URL = f"postgresql://{DB_USER}:{DB_PASS}@{DB_HOST}:5432/{DB_NAME}"
engine_args = {
"pool_size": 20, # Maximum number of database connections in the pool
"max_overflow": 50, # Maximum number of connections that can be created beyond the pool_size
"pool_timeout": 30, # Timeout value in seconds for acquiring a connection from the pool
"pool_recycle": 1800, # Recycle connections after this number of seconds (optional)
"pool_pre_ping": False, # Enable connection health checks (optional)
}
app.add_middleware(DBSessionMiddleware, db_url=DB_URL, engine_args=engine_args)
# routers for controllers
app.include_router(contact_router, prefix="/api/contact")
# Configure CORS middleware
origins = [
"*", # Allow all origins
]
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["X-Request-ID"],
)
database = Database(DB_URL)
engine = database.get_engine()
@app.get("/api/health")
def health_check():
return {"status": "ok"}