@@ -210,11 +210,24 @@ def _reset_app_cache_marker(self):
210
210
to all the running instances.
211
211
"""
212
212
213
+ @api .model
214
+ def get_endpoint (self , root_path ):
215
+ # try to match the request url with the most similar endpoint
216
+ endpoints_by_length = self .search ([]).sorted (
217
+ lambda fe : len (fe .root_path ), reverse = True
218
+ )
219
+ endpoint = False
220
+ while endpoints_by_length :
221
+ candidate_endpoint = endpoints_by_length [0 ]
222
+ if root_path .startswith (candidate_endpoint .root_path ):
223
+ endpoint = candidate_endpoint
224
+ break
225
+ endpoints_by_length -= candidate_endpoint
226
+ return endpoint or None
227
+
213
228
@api .model
214
229
def get_app (self , root_path ):
215
- record = self .search ([("root_path" , "=" , root_path )])
216
- if not record :
217
- return None
230
+ record = self .get_endpoint (root_path )
218
231
app = FastAPI ()
219
232
app .mount (record .root_path , record ._get_app ())
220
233
self ._clear_fastapi_exception_handlers (app )
@@ -238,7 +251,7 @@ def _clear_fastapi_exception_handlers(self, app: FastAPI) -> None:
238
251
@api .model
239
252
@tools .ormcache ("root_path" )
240
253
def get_uid (self , root_path ):
241
- record = self .search ([( " root_path" , "=" , root_path )] )
254
+ record = self .get_endpoint ( root_path )
242
255
if not record :
243
256
return None
244
257
return record .user_id .id
0 commit comments