Reverse proxy support for custom server base path
My self hosted apps are typically under a https://mydomain.com/app path. The web app should have a way of handling requests under a base path which is not necessarily root.
This is my first attempt.
I believe some more code tweaking is needed since not all requests seem to go through the python server's handler.
Inputs and suggestions are highly appreciated as I'd like to be able to host a variant of this app with configurability on reverse proxies.
Thanks!
for this one:
not all requests seem to go through the python server's handler
I think there are a few things to look at:
- the frontend is explicit in its setting of the path via
history.pushState. The code is:const newUrl = `/${activeGraph.prefix}/${words}`;, so we might need a globalbase_pathvariable on the frontend as well, so that we could setnewUrlto${basePath}/${activeGraph.prefix}/${words}. I could help with this if needed, and then presumably it could be overridden in the same way we'd overrideUSE_FIREBASE(let me know if that doesn't make sense and I can dig into it a bit more)- related: back when I hosted HanziGraph on github pages, I recall I changed most of the paths in the JS to be
./instead of/, since the paths would've beenmreichhoff.github.io/HanziGraph/whatever. - The service worker might also have to change to include the base path, as it also has a list of files to cache. Same with
data-load.js.
- related: back when I hosted HanziGraph on github pages, I recall I changed most of the paths in the JS to be
history.pushStatechanges the path in the browser's URL bar, but it doesn't trigger a separate request to the server, so perhaps that's part of the discrepancy you're noticing? Or feel free to let me know which files you weren't seeing requested for help debugging!
Yes I only remember that after "cold booting" the server, subsequent (and repeated) requests were no longer hitting the server as often, likely due to browser caching? I can fire up that debug server again and give you some examples if it helps.
So it seems there is a bit of work needed on the core code to fully support base_path am I right?
Thanks for considering looking into this.
For the time being I opened an extra port for this app on my server - long term however I'd like it more secure behind a reverse proxy (+certificates), the base path will become very handy especially with Docker in the mix.
So it seems there is a bit of work needed on the core code to fully support base_path am I right?
yes, that's correct, though I have this possibly silly idea that we could just run some string replacements with sed in your docker setup. I would just need a common pattern for the paths in the JS files
Cool, quick wins are good.
Hey hey.
I'm realising there's one more reason to support reverse proxy: HanziGraph doesn't allow saving the dictionary offline and enabling the tool offline, unless the connection is over https (unless I'm wrong?). The reverse proxy would enable the certificates for https.
nah, you're right: service workers are https-only, and I lean on those for offline support.
Did you want to try writing in some sed in the dockerfile in this PR, or you want me to give it a shot?
If you can please give it a shot, as I wouldn't know what I am doing :)