-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
67 lines (58 loc) · 1.52 KB
/
wsgi.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api import chat_router, vision_router
import os
from logging.config import dictConfig
from api.config.logger.log_config import LogConfig
def create_app() -> FastAPI:
"""
Create the FastAPI application.
Returns
-------
app : FastAPI
The FastAPI instance.
"""
app = FastAPI(
title="AutoMate Gen-AI Backend Service",
description="Backend service of AutoMate Gen-AI application. Includes API endpoints for chat and video operations.",
version="0.0.1",
)
init_routers(app)
init_logger()
configure_middleware(app)
return app
def init_routers(app: FastAPI) -> None:
"""
Initialize routers for the application.
Parameters
----------
app : FastAPI
The FastAPI instance to attach the routers to.
Returns
-------
None
"""
app.include_router(chat_router)
app.include_router(vision_router)
def init_logger():
dictConfig(LogConfig().dict())
def configure_middleware(app: FastAPI) -> None:
"""
Configure middleware for the application.
Parameters
----------
app : FastAPI
The FastAPI instance to configure the middleware for.
Returns
-------
None
"""
origins = os.getenv("CORS_ORIGINS", "*").split(",")
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"]
)
app = create_app()