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

[Feature] Set BASE_URL in MQTTX-Web on startup #1575

Closed
pengowray opened this issue Jan 30, 2024 · 4 comments · Fixed by #1619
Closed

[Feature] Set BASE_URL in MQTTX-Web on startup #1575

pengowray opened this issue Jan 30, 2024 · 4 comments · Fixed by #1619
Assignees
Labels
feature This pr is a feature web MQTTX Web
Milestone

Comments

@pengowray
Copy link

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 pengowray added the feature This pr is a feature label Jan 30, 2024
@github-project-automation github-project-automation bot moved this to Backlog in MQTTX Jan 30, 2024
@pengowray pengowray changed the title [Feature] Set BASE_URL in MQTTX-Web on startup (or from env) [Feature] Set BASE_URL in MQTTX-Web on startup Jan 30, 2024
@ysfscream ysfscream added the web MQTTX Web label Jan 31, 2024
@Red-Asuka
Copy link
Member

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
Copy link
Member

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

@ysfscream
Copy link
Member

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.

@pengowray
Copy link
Author

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.

@DM1-1 DM1-1 linked a pull request Apr 3, 2024 that will close this issue
2 tasks
@ysfscream ysfscream moved this from Backlog to In Progress in MQTTX Apr 8, 2024
@ysfscream ysfscream added this to the v1.10.0 milestone Apr 9, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in MQTTX Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This pr is a feature web MQTTX Web
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants