[Hubs Cloud] Fix local assets path and upload proxy for localhost #5146
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a couple of issues that occur when running a local client against a Hubs Cloud stack.
The change to BASE_ASSETS_PATH ought to be explained further, so I will do that here.
In Hubs-Foundation/reticulum#508 we introduced a security fix that prevents uploaded files from being served from the primary domain. Uploads must now be served from secondary domains in order to keep them isolated.
This security change worked well with the frontend hubs client, but it broke some aspects of the admin panel. The admin panel issues were fixed by introducing an UPLOADS_HOST environment variable (#4565) which contained the secondary domain that uploads are typically served from.
However, the UPLOADS_HOST variable did not work in scenarios where Hubs Cloud stacks used Cloudflare as a CDN, since uploads were being served via the CDN, which is a separate domain. We fixed the issue with Cloudflare in #5100 by using the BASE_ASSETS_PATH configuration variable, which did include the correct Cloudflare domain.
Unfortunately, that fix also broke another scenario, when users were running local clients against a Hubs Cloud stack. BASE_ASSETS_PATH was previously never used locally, so it was undefined, which causes a null reference error in
getUploadsUrl
. We then fixed this in #5125 by defining BASE_ASSETS_PATH locally.This caused yet another problem. When running locally, BASE_ASSETS_PATH is set to "/" by default in
.defaults.env
. This breaks the physics system, since it relies on BASE_ASSETS_PATH to load the Ammo.js WASM bundle, and expects BASE_ASSETS_PATH to be an absolute URL, not a relative one. This PR fixes that issue.Arguably, we could have fixed the null reference error in
getUploadsUrl
by doing a null check instead of defining BASE_ASSETS_PATH, but it might be better to move forward at this point, instead of reverting the change.