-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
executable file
·42 lines (31 loc) · 1.08 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
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from logger import logger
from pkg.src.config.database import get_session
from pkg.src.middleware.cors import cors_middleware
# inbuilt packages
from pkg.src.routes import health, unit_test, doc_generation, validate_openai
@asynccontextmanager
async def lifespan(_: FastAPI):
"""
# trigger everytime the app starts
"""
db_session = get_session()
if not db_session:
logger.error("Database connection failed!")
return
logger.info("Database connected!")
yield
app = FastAPI(lifespan=lifespan)
# cors middleware
cors_middleware(app)
# routes
app.include_router(health.router, tags=["Health"], prefix="/api")
app.include_router(validate_openai.router, tags=["OpenAI Validation"], prefix="/api")
app.include_router(unit_test.router, tags=["Unit Test Generation"], prefix="/api")
app.include_router(
doc_generation.router, tags=["Documentation Generation"], prefix="/api"
)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)