Fix reverse proxy subpath support using External_Webserver_address#4513
Fix reverse proxy subpath support using External_Webserver_address#4513Leolebleis wants to merge 2 commits intoplan-player-analytics:masterfrom
Conversation
When Plan runs behind a reverse proxy at a subpath (e.g. /minecraft/stats/), the External_Webserver_address config was only used as a fallback when the webserver was disabled. This meant HTML asset paths stayed root-relative (/static/...) and PLAN_BASE_ADDRESS was injected with the internal address, breaking both static asset loading and React Router navigation. Add Addresses.getExternalAddress() that returns the configured external address when valid, and prefer it in both BundleAddressCorrection (for HTML/JS/CSS path rewriting) and ResponseFactory (for PLAN_BASE_ADDRESS injection). This gives the JS the correct protocol and subpath for reverse proxy setups.
The Vite __vitePreload helper uses `return"/"+l` to construct asset URLs. When deployed at a subpath, this produces root-relative paths like `/static/...` instead of `/plan/static/...`, causing CSS preload failures. Replace the hardcoded "/" prefix with the base path when configured.
|
Alternative_IP.Address is used for this purpose - External address is intended for use when Export is being used |
@AuroraLS3 Ah I see, thanks! I originally tried
Would you prefer a different approach — e.g. making |
|
When using reverse-proxy based https you can set up Plan to assume https with proxy-mode: https://github.com/plan-player-analytics/Plan/wiki/SSL-Certificate-%28HTTPS%29-Set-Up#if-behind-a-proxy |
|
This test covers regressions for reverse-proxy behind subdirectory |
|
Ah ok thank you :) I need to AFK for a bit but will check later, I think I tried that and ran into issues Will get back to you asap! |
|
The issue you ran into is likely a caching issue (Another user was having this today) - The javascript file that contains PLAN_BASE_ADDRESS is cached by the browser and change to proxy mode is not reflected in the address until cache is cleared. Why this issue wasn't run into before is that the old bugged code defaulted to using relative address when the configured address "Didn't match", which meant that the site still loaded, but now with the bug fixed it detects the address as correct and tries to serve HTTP content in HTTPS website which the Browser blocks. This needs to be fixed in the cache logic for static javascript files rather than configuration settings, so I will close this PR - I have applied this fix in 1a8bac8 |
Your checklist for this pull request
/Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Contributors.javaDescription
When Plan runs behind a reverse proxy at a subpath (e.g.
/minecraft/stats/),External_Webserver_addresswas only consulted when the webserver was disabled. With the webserver running, both HTML asset paths andPLAN_BASE_ADDRESSused the internal address (e.g.http://localhost:8804), breaking static asset loading, React Router navigation, and API calls (wrong protocol/path).Changes:
Addresses.getExternalAddress()— new method returningExternal_Webserver_addresswhen set to a non-default valueBundleAddressCorrection.getWebserverBasePath()— prefers external address base path for HTML/JS/CSS path rewritingResponseFactory.replaceMainAddressPlaceholder()— prefers external address forPLAN_BASE_ADDRESSinjectionTested on a live deployment (Plan v5.7 b3288 behind nginx HTTPS proxy at a subpath). Unit tests included.