-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
45 lines (37 loc) · 1.38 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
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.core.config import settings
from app.api.v1.router import get_api_router
from pydantic import BaseModel
from typing import List, Optional
def create_application() -> FastAPI:
"""Создает и настраивает экземпляр FastAPI приложения."""
application = FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
openapi_url=f"{settings.API_V1_STR}/openapi.json",
docs_url=f"{settings.API_V1_STR}/docs",
redoc_url=f"{settings.API_V1_STR}/redoc"
)
application.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
api_router = get_api_router()
application.include_router(api_router, prefix=settings.API_V1_STR)
return application
app = create_application()
"""
Настройка CORS middleware для обработки кросс-доменных запросов.
Внимание: в продакшене следует указать конкретные разрешенные домены вместо "*".
"""
class ActivityCreate(BaseModel):
name: str
level: int
parent_id: Optional[int] = None
children: List = []
class Config:
from_attributes = True