Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

forward query to _ws_handler #609

Open
HelgeGehring opened this issue Oct 9, 2024 · 3 comments
Open

forward query to _ws_handler #609

HelgeGehring opened this issue Oct 9, 2024 · 3 comments

Comments

@HelgeGehring
Copy link

HelgeGehring commented Oct 9, 2024

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

@jourdain
Copy link
Collaborator

jourdain commented Oct 9, 2024

You have several paths to handle it.

  1. Doing at startup: when you deploy your application with docker, the url args can be used in the args of the application. (see discussion)
  2. Doing on the client: When the client connect, it will call a method on the server to do something about the URL. (see discussion)

@HelgeGehring
Copy link
Author

Thanks for the quick reply!

I'll have a look at 1!
2. doesn't really seem to me a solution for my case, as I'd like to have things loaded before showing the gui.

would there be a reason to not just forward the parameters?
return aiohttp.web.HTTPFound(f"index.html?{request.query_string}") already forwards it to the html-page such that i think it would be just a simple addition to the .js file to forward it to /ws?

Thanks!

@jourdain
Copy link
Collaborator

jourdain commented Oct 9, 2024

trame.tools.serve is not meant to be used in real production especially when VTK/ParaView is involved. If trame is used for doing dashboards then that runner could make sense. But either way, we are more on a process based separation than a async task based separation. So that url arg is already taking care at the launcher stage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants