Версия 0.0.2
This commit is contained in:
commit
7b9c998224
530 changed files with 424916 additions and 0 deletions
29
SRV/config/cors.py
Normal file
29
SRV/config/cors.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from fastapi import FastAPI
|
||||
from starlette.middleware.cors import CORSMiddleware
|
||||
|
||||
|
||||
class CORSMiddlewareConfig:
|
||||
"""
|
||||
Класс для настройки CORS политики в FastAPI
|
||||
"""
|
||||
def __init__(self, app: FastAPI) -> None:
|
||||
""" Инициализируем приложение FastAPI и список допустимых CORS-оригинов """
|
||||
self.app = app
|
||||
self.origins = [
|
||||
"http://localhost.tiangolo.com",
|
||||
"https://localhost.tiangolo.com",
|
||||
"http://localhost",
|
||||
"http://localhost:8080",
|
||||
"http://localhost:5174",
|
||||
"http://localhost:5173",
|
||||
]
|
||||
|
||||
def add_cors_middleware(self) -> None:
|
||||
""" Добавляем CORS в приложение FastAPI """
|
||||
self.app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=self.origins,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue