@@ -10,33 +10,40 @@ class APIController:
1010 routes = []
1111
1212 def __init__ (self ,
13- app : FastAPI = None ,
13+ app : FastAPI ,
1414 cors_origins = None ,
15+ generate_options_endpoints = True ,
16+ generate_head_endpoints = True
1517 ) -> None :
16- if app is None :
17- app = FastAPI ()
18- self .__app = app
18+ self . __app = app
19+ self . __generate_options_endpoints = generate_options_endpoints
20+ self .__generate_head_endpoints = generate_head_endpoints
1921 if cors_origins is not None :
2022 self .__add_cors (cors_origins )
23+
2124 self .__register_routes ()
2225
2326 def __register_routes (self ) -> None :
2427 container = DIContainer (Registry ())
2528 registry = container .get (Registry )
26- self .__routes = registry .get_routes ()
29+ self .__routes = registry .get_routes ()
30+
2731 for func , path , method in self .__routes :
28- bound_method = getattr (self , func .__name__ )
32+ if hasattr (self ,'_route_prefix' ):
33+ path = self ._route_prefix + path
34+ bound_method = getattr (self , func .__name__ )
2935 self .__add_route (bound_method , method , path )
3036
31- self .__add_options_endpoints ()
37+ if self .__generate_options_endpoints :
38+ self .__add_options_endpoints ()
3239
3340 def __add_route (self , bound_method , method , path ):
3441 self .__app .add_api_route (
3542 path = path ,
3643 endpoint = bound_method ,
3744 methods = [method .value ]
3845 )
39- if method .value == 'GET' :
46+ if method .value == 'GET' and self . __generate_head_endpoints :
4047 self .__add_head (path )
4148
4249 def __add_head (self , path ):
0 commit comments