11import logging
2+ import textwrap
23from collections import OrderedDict
34
45from aiohttp import web
@@ -43,7 +44,7 @@ def _discover_product_by_request_header(request: web.Request) -> str | None:
4344 return None
4445
4546
46- def _get_diagnose_msg (request : web .Request ):
47+ def _get_debug_msg (request : web .Request ):
4748 return "\n " .join (
4849 [
4950 f"{ request .url = } " ,
@@ -56,9 +57,6 @@ def _get_diagnose_msg(request: web.Request):
5657 )
5758
5859
59- _INCLUDE_PATHS : set [str ] = {"/static-frontend-data.json" , "/socket.io/" }
60-
61-
6260@web .middleware
6361async def discover_product_middleware (request : web .Request , handler : Handler ):
6462 """
@@ -71,8 +69,9 @@ async def discover_product_middleware(request: web.Request, handler: Handler):
7169 if (
7270 # - API entrypoints
7371 # - /static info for front-end
72+ # - socket-io
7473 request .path .startswith (f"/{ API_VTAG } " )
75- or request .path in _INCLUDE_PATHS
74+ or request .path in { "/static-frontend-data.json" , "/socket.io/" }
7675 ):
7776 request [RQ_PRODUCT_KEY ] = (
7877 _discover_product_by_request_header (request )
@@ -83,22 +82,20 @@ async def discover_product_middleware(request: web.Request, handler: Handler):
8382 else :
8483 # - Publications entrypoint: redirections from other websites. SEE studies_access.py::access_study
8584 # - Root entrypoint: to serve front-end apps
86- # request.path.startswith("/study/")
87- # or request.path.startswith("/view")
88- # or request.path == "/" )
85+ assert ( # nosec
86+ request .path .startswith ("/dev/" )
87+ or request .path .startswith ("/study/" )
88+ or request .path .startswith ("/view" )
89+ or request .path == "/"
90+ )
8991 request [RQ_PRODUCT_KEY ] = _discover_product_by_hostname (
9092 request
9193 ) or _get_default_product_name (request .app )
9294
93- # FIXME: session[product]
94- # if product_session := get_session(request).get('product_name'):
95- # assert get_product_name(request) == product_session
96-
95+ # TODO: remove this!!!
9796 _logger .warning (
98- "\n %s\n %s\n %s\n " ,
99- "------------------TESTING-------------------" ,
100- _get_diagnose_msg (request ),
101- "-------------------------------------------" ,
97+ "Product middleware result: \n %s\n " ,
98+ textwrap .indent (_get_debug_msg (request ), " " ),
10299 )
103100 assert request [RQ_PRODUCT_KEY ] # nosec
104101
0 commit comments