lavkach3
26 строк · 835.0 Байт
1from fastapi import FastAPI
2from starlette.datastructures import QueryParams
3from starlette.exceptions import HTTPException
4from starlette.middleware.base import BaseHTTPMiddleware
5from starlette.requests import Request, HTTPConnection
6from starlette.responses import Response
7from starlette.types import Scope, Receive, Send, ASGIApp
8from core.config import config
9from core.fastapi.adapters import BaseAdapter
10
11
12class env:
13...
14
15
16class CompanyMidlleWare:
17def __init__(self, app: ASGIApp, *args, **kwargs):
18self.app = app
19
20async def __call__(self, scope: Scope, receive: Receive, send: Send):
21conn = HTTPConnection(scope)
22e = env()
23for i, v in config.services.items():
24e.__setattr__(i, BaseAdapter(conn, i))
25scope['env'] = e
26await self.app(scope, receive, send)
27
28