forked from pAI-OS/paios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (36 loc) · 1.3 KB
/
app.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
from pathlib import Path
from connexion import AsyncApp
from connexion.resolver import MethodResolver
from connexion.middleware import MiddlewarePosition
from starlette.middleware.cors import CORSMiddleware
from backend.db import init_db
def create_backend_app():
# Initialize the database
init_db()
apis_dir = Path(__file__).parent.parent / 'apis' / 'paios'
connexion_app = AsyncApp(__name__, specification_dir=apis_dir)
allow_origins = [
'http://localhost',
'http://localhost:3080',
'http://localhost:5173'
]
# Add CORS middleware
connexion_app.add_middleware(
CORSMiddleware,
position=MiddlewarePosition.BEFORE_EXCEPTION,
allow_origins=allow_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["Content-Range", "X-Total-Count"],
)
# Add API with validation
connexion_app.add_api(
'openapi.yaml',
resolver=MethodResolver('backend.api'),
resolver_error=501,
# TODO: Validation has a performance impact and may want to be disabled in production
validate_responses=True, # Validate responses against the OpenAPI spec
strict_validation=True # Validate requests strictly against the OpenAPI spec
)
return connexion_app