trame
trame copied to clipboard
forward query to _ws_handler
I'd like to load different files based on the query string
Modiefied part of https://github.com/Kitware/trame/blob/master/trame/tools/serve.py :
async def _index_handler(self, request):
if request.query_string:
print(request.query)
return aiohttp.web.HTTPFound(f"index.html?{request.query_string}")
return aiohttp.web.HTTPFound("index.html")
async def _ws_handler(self, request):
print(request.query)
The first print prints the query, the second doesn't. I'd need the information in the second part to use it for initializing the app, right?
Describe the solution you'd like
In the index-.....js
i find
xr=`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.hostname}:${window.location.port}${mr("/ws")}`;
I'd guess if we would add there the query string, it should be forwarded such the second print would also print it?
Describe alternatives you've considered
What I do right now as a workaround:
...
self.queries = []
async def _index_handler(self, request):
if request.query_string:
self.queries.append(request.query_string)
return aiohttp.web.HTTPFound(f"index.html?{request.query_string}")
return aiohttp.web.HTTPFound("index.html")
async def _ws_handler(self, request):
print(self.queries.pop())
Does more or less the job, but it's for sure not a solution