-
Notifications
You must be signed in to change notification settings - Fork 575
/
Copy pathreadonly.py
49 lines (39 loc) · 1.34 KB
/
readonly.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
import logging
from contextlib import asynccontextmanager
import sentry_sdk
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.admin import admin_router_readonly, health_router, schema_router_readonly
from app.config.config import config
from app.entrypoints.web import chat_router_readonly
from models.db import init_db
# init logger
logger = logging.getLogger(__name__)
if config.sentry_dsn:
sentry_sdk.init(
dsn=config.sentry_dsn,
sample_rate=config.sentry_sample_rate,
traces_sample_rate=config.sentry_traces_sample_rate,
profiles_sample_rate=config.sentry_profiles_sample_rate,
environment=config.env,
release=config.release,
server_name="intent-readonly",
)
@asynccontextmanager
async def lifespan(app: FastAPI):
await init_db(**config.db)
logger.info("Readonly API server starting")
yield
logger.info("Readonly API server shutting down")
app = FastAPI(lifespan=lifespan)
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)
app.include_router(health_router)
app.include_router(admin_router_readonly)
app.include_router(schema_router_readonly)
app.include_router(chat_router_readonly)