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

Allow hosting behind reverse proxy with prefixed path #258

Closed
wants to merge 1 commit into from
Closed

Allow hosting behind reverse proxy with prefixed path #258

wants to merge 1 commit into from

Conversation

rodja
Copy link
Collaborator

@rodja rodja commented May 24, 2021

To be hosted behind a reverse proxy like Traefik or nginx Justpy needs to be aware about the prefixed path. These proxies provide a X-Forwarded-Prefix header for this purpose. On the browser side we can use the location.pathname to access the prefix and establish the connection accordingly.

@rodja rodja mentioned this pull request May 24, 2021
rodja added a commit to zauberzeug/nicegui that referenced this pull request May 24, 2021
@elimintz
Copy link
Collaborator

Thank you for this. I see why it is important and would be valuable in the package. Unfortunately, I do not have the experience nor the setup to test this if it is incorporated into justpy. Just thinking out loud, can this made into a standalone package, a version of justpy for reverse proxies?

@rodja
Copy link
Collaborator Author

rodja commented May 25, 2021

can this made into a standalone package, a version of Justpy for reverse proxies?

Interesting! It would still require some extensive hook-points within Justpy:

  1. We would need to set the page_options.prefix_path externally according to the current request header. Therefore the WebPage needs a callback function on_request or similar with the request object and page_options as parameter. Still, the templates need to interpret the path_prefix.
  2. We also need to move the websocket path determination from Javascript to Python (see
    7f86f0a#diff-9b0be2bc0877639d984fb3df3beb313ea2bbab0f5dc828423dbd537c500e588f). Maybe as an other callback WebPage.get_websocket_uri? It should have the current request object as parameter to access request.url.path, request.url.scheme and similar.

This would be much better than my hack for our NiceGui library which is based on Justpy. Currently I saw no other option then to apply the patch into the installed Justpy library within a docker container. Obviously this should be replaced as soon as possible.

@elimintz
Copy link
Collaborator

Give me a few days to think this over and figure out how much change is needed in the code. I was thinking more along the following lines: Once a version of JustPy is ready, if this is something worth your time, you would make the changes required and test the package in your configuration. Then you could publish a package called for example justpy-reverse-proxy for people to use.

Since you have experience with docker, perhaps you could define a container that would make it simple for people to deploy JustPy? Any ideas in general on how to make deployment as simple as possible would be much appreciated. A command that takes a JustPy project and deploys it to one of the cloud service providers would be a huge improvement to the project.

@rodja
Copy link
Collaborator Author

rodja commented May 26, 2021

I found a solution which only needs modifications in the template dir and hence can be used on top of Justpy without code modifications. I just copied the original templates dir and applied this changes.

@rodja
Copy link
Collaborator Author

rodja commented May 26, 2021

Since you have experience with docker, perhaps you could define a container that would make it simple for people to deploy JustPy? Any ideas in general on how to make deployment as simple as possible would be much appreciated. A command that takes a JustPy project and deploys it to one of the cloud service providers would be a huge improvement to the project.

I started a new discussion about the dockerization at #260

@elimintz
Copy link
Collaborator

I found a solution which only needs modifications in the template dir and hence can be used on top of Justpy without code modifications. I just copied the original templates dir and applied this changes.

This is great, thank you. I will include this in the next version of JustPy.

This pull request was closed.
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

Successfully merging this pull request may close these issues.

2 participants