Skip to content

Inject runtime URLs in the back-end served index.html - #64

Merged
MartinaeyNL merged 5 commits into
mainfrom
bugfix/websocket-subscription
Mar 26, 2026
Merged

Inject runtime URLs in the back-end served index.html#64
MartinaeyNL merged 5 commits into
mainfrom
bugfix/websocket-subscription

Conversation

@dominiquekleeven

@dominiquekleeven dominiquekleeven commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Closes #65

Currently the front-end bundle contains relative URLs that are embedded during its built process. This bundle is then served by the back-end service.

This change allows the back-end to dynamically inject the configured server URL environment variables into the served index.html which is then used by the front-end as runtime config. This is more flexible and reliable than relying on embedded relative URLs. It only injects the necessary variables and does not expose anything else.

The change also resolves an issue where the WS subscription would fail since the ManagerConfig expects the managerUrl to be absolute (e.g. containing the full address), to determine whether it should use WS or WSS.

this._endpointUrl = (managerUrl.startsWith("https:") ? "wss" : "ws") + "://" + managerUrl.substr(managerUrl.indexOf("://") + 3) + "/websocket/events";

@dominiquekleeven dominiquekleeven added Bug Error or issue in the system Enhancement Improvement of an existing feature labels Mar 23, 2026
@dominiquekleeven dominiquekleeven changed the title Inject absolute URLs in served front-end bundle Inject runtime URLs in the back-end served index.html Mar 23, 2026
@dominiquekleeven

Copy link
Copy Markdown
Contributor Author

Deployed on test4

@MartinaeyNL MartinaeyNL left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this PR is fine with me.
I've only got two minor comments to simplify the scope to window, instead of global variables.
I'm not sure whether we should also follow a similar practice for the OpenRemote repository,
but this pattern is perfectly fine within a specific project like this.

Comment thread frontend/src/index.ts
import './components/alert-message';

const DEFAULT_MANAGER_CONFIG: ManagerConfig = {
managerUrl: ML_OR_URL || '/',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you removed this fallback to allow ML_OR_URL to be an empty value.
I think if you replace || with ??, it should still work, because it's a better null check.

managerUrl: MR_OR_URL ?? '/'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses nullish coalesce now, thanks! I keep forgetting it exists haha.

Comment thread src/service_ml_forecast/api/web_route.py
@MartinaeyNL
MartinaeyNL merged commit 130751c into main Mar 26, 2026
2 checks passed
@MartinaeyNL
MartinaeyNL deleted the bugfix/websocket-subscription branch March 26, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Error or issue in the system Enhancement Improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebSocket subscription fails due to 'insecure operation'

2 participants