MQTTX icon indicating copy to clipboard operation
MQTTX copied to clipboard

[Feature] Set BASE_URL in MQTTX-Web on startup

Open pengowray opened this issue 1 year ago • 4 comments

Motivation

It's not a huge issue but thought I'd try getting MQTTX working inside home assistant (HA), and realize it could be very easy with this small tweak to MQTTX, and other users might find the same useful. (Or maybe I'm missing some easy way to do it)

Trying to set up MQTTX Web as an "addon" in HA, which displays the page in a frame. In HA's framework, perhaps for security or just for architectural reasons, mqttx is required to have a different BASE_URL each time its docker container is started.

Is there a way to set BASE_URL on start up? or otherwise could this option be added?

I see there's an option to set a BASE_URL when compiling with yarn, but it would be much easier to base something off something like the existing mttqx-web docker container rather than recreating the whole build environment.

Detailed design

A solution would require some way to set BASE_URL on startup, either from an environment variable, .env.local file, or http-server --base=... or the like.

Similarly, it would be great if VUE_APP_PAGE_TITLE and VUE_APP_PAGE_DESCRIPTION could be dynamically set on startup.

Also is there a way to set up a default server to connect to?

Alternatives

Maybe I could just work out a minimal yarn setup and re-build before running, or alter the URLs dynamically with a dedicated instance of nginx, but these seem like comparatively heavy weight solutions which add a lot of complexity.

Cheers.

pengowray avatar Jan 30 '24 13:01 pengowray

Thank you for your input. Currently, we only provide bundled static files through the Docker image, and these files require configurations to be provided before the bundling process. If we want to support modifications of these configurations through Docker parameters, it might require us to include the source code in the image and compile it upon container startup. This could result in an increased image size and longer startup time. Considering that some users might need this feature, we are planning to expose some configuration options to the users and document this accordingly. Users could then build their own images by modifying these configuration files.

Red-Asuka avatar Feb 02 '24 06:02 Red-Asuka

Hi @ysfscream, could you please share your thoughts on this? Thanks!

Red-Asuka avatar Feb 02 '24 07:02 Red-Asuka

Hi, all. Thanks for using the MQTTX, and I understand the motivation behind the request to dynamically modify the Base URL after Docker restarts, although it seems to be an uncommon requirement. The Base URL for web applications is typically configured before production. Once built, these configurations are embedded within the static files, making it impractical to alter them without a rebuild. This approach ensures ease of deployment and application stability.

Given the challenges associated with directly modifying the Base URL in production, an alternative solution could be to utilize scripts to dynamically set the Base URL during the build process. This method would automate the process of cloning the code, updating the Base URL setting, and then rebuilding the Docker image whenever changes are needed. While this adds a layer of complexity to the deployment process, it offers the required flexibility without needing to modify production configurations directly.

I'm not familiar with the specifics of Home Assistant (HA), but if the HA environment allows, this script-based automation approach for building and deploying could be a viable solution. This way, we can accommodate the need to adjust the Base URL upon container restart while maintaining overall system stability and security.

ysfscream avatar Feb 02 '24 08:02 ysfscream

Thanks for the replies.

So, I think to save rebuilding each time I'll need to make a build with Base_URL to some random text like %%ingress_entry%% and use sed to replace that text with the correct config when bringing up the container.

Hmm. Might be simpler just to bundle with nginx and get it to redirect urls.

OK thanks.

pengowray avatar Feb 02 '24 23:02 pengowray