|
| 1 | +from osbot_fast_api.api.middlewares.Middleware__Http_Request import Middleware__Http_Request |
| 2 | +from osbot_fast_api.api.middlewares.Middleware__Request_ID import Middleware__Request_ID |
1 | 3 | from osbot_fast_api.schemas.Schema__Fast_API__Config import Schema__Fast_API__Config |
2 | 4 | from osbot_utils.type_safe.Type_Safe import Type_Safe |
3 | 5 | from osbot_utils.decorators.lists.index_by import index_by |
|
6 | 8 | from osbot_utils.utils.Json import json_loads, json_dumps |
7 | 9 | from starlette.staticfiles import StaticFiles |
8 | 10 | from osbot_fast_api.api.Fast_API__Offline_Docs import Fast_API__Offline_Docs, FILE_PATH__STATIC__DOCS, URL__STATIC__DOCS, NAME__STATIC__DOCS |
9 | | -from osbot_fast_api.api.events.Fast_API__Http_Events import Fast_API__Http_Events |
10 | 11 | from osbot_fast_api.api.routes.Routes__Config import Routes__Config |
11 | 12 | from osbot_fast_api.api.routes.Routes__Set_Cookie import Routes__Set_Cookie |
12 | 13 | from osbot_fast_api.schemas.consts.consts__Fast_API import ENV_VAR__FAST_API__AUTH__API_KEY__NAME, ENV_VAR__FAST_API__AUTH__API_KEY__VALUE |
13 | 14 |
|
14 | 15 |
|
15 | 16 |
|
16 | 17 | class Fast_API(Type_Safe): |
17 | | - # base_path : Safe_Str__Fast_API__Route__Prefix = '/' |
18 | | - # add_admin_ui : bool = False |
19 | | - # docs_offline : bool = True |
20 | | - # enable_cors : bool = False |
21 | | - # enable_api_key : bool = False |
22 | | - # default_routes : bool = True |
23 | | - # name : Safe_Str__Fast_API__Name = None |
24 | | - # version : Safe_Str__Version = version__osbot_fast_api |
25 | | - # description : Safe_Str__Text = None |
26 | 18 | config : Schema__Fast_API__Config |
27 | | - http_events : Fast_API__Http_Events |
28 | 19 | server_id : Random_Guid |
29 | 20 |
|
30 | 21 | def __init__(self, **kwargs): |
31 | 22 | super().__init__(**kwargs) |
32 | 23 | if not self.config.name: |
33 | | - self.config.name = self.__class__.__name__ |
34 | | - self.http_events.fast_api_name = self.config.name |
| 24 | + self.config.name = self.__class__.__name__ # this makes the api name more user friendly |
35 | 25 |
|
36 | 26 | # todo: improve the error handling of validation errors (namely from Type_Safe_Primitive) |
37 | 27 | # see code example in https://claude.ai/chat/f443e322-fa43-487f-9dd9-2d4cfb261b1e |
@@ -166,8 +156,8 @@ def routes_paths_all(self): |
166 | 156 |
|
167 | 157 |
|
168 | 158 | def setup_middlewares(self): # overwrite to add more middlewares |
| 159 | + self.setup_middleware__request_id () # sets the 'fast-api-request-id' headers |
169 | 160 | self.setup_middleware__detect_disconnect() |
170 | | - self.setup_middleware__http_events () |
171 | 161 | self.setup_middleware__cors () |
172 | 162 | self.setup_middleware__api_key_check () |
173 | 163 | return self |
@@ -230,12 +220,8 @@ def setup_middleware__detect_disconnect(self): |
230 | 220 |
|
231 | 221 | self.app().add_middleware(Middleware__Detect_Disconnect) |
232 | 222 |
|
233 | | - def setup_middleware__http_events(self): |
234 | | - from osbot_fast_api.api.middlewares.Middleware__Http_Request import Middleware__Http_Request |
235 | | - |
236 | | - self.app().add_middleware(Middleware__Http_Request , http_events=self.http_events) |
237 | | - return self |
238 | | - |
| 223 | + def setup_middleware__request_id(self): |
| 224 | + self.app().add_middleware(Middleware__Request_ID) |
239 | 225 |
|
240 | 226 | def user_middlewares(self, include_params=True): |
241 | 227 | import types |
|
0 commit comments