fix: guard docker-entrypoint sed against empty env vars#45
Merged
Conversation
The docker-entrypoint.sh unconditionally ran sed to replace API URLs
in the JS bundle, even when REACT_APP_API_URL and REACT_APP_WEBSOCKET_URL
were not set as runtime env vars. This replaced the build-time defaults
(http://localhost/api, ws://localhost) with empty strings, breaking all
API calls — fetch('') hits nginx root and returns index.html instead of
JSON, causing 'undefined is not an object' crashes throughout the app.
Fix: only run sed replacement when the env vars are actually set (non-empty).
When not set, the build-time defaults remain intact and work correctly
with the existing nginx proxy_pass configuration.
Fixes the regression introduced in f899d10.
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
homeles
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Commit
f899d10addeddocker-entrypoint.shas the container ENTRYPOINT to support runtime API URL replacement. However, the script unconditionally runssedto replace the build-time URL defaults (http://localhost/api,ws://localhost) with the values ofREACT_APP_API_URLandREACT_APP_WEBSOCKET_URL.When running via
docker-compose, the client service does not pass these as runtime env vars (they are only buildARGs). So at container startup:REACT_APP_API_URL→ empty stringREACT_APP_WEBSOCKET_URL→ empty stringThe
sedreplaces all API URLs in the JS bundle with empty strings. Everyfetch()call then hits""→ resolves to the nginx root → returnsindex.html(HTML) instead of JSON → the app crashes withTypeError: undefined is not an object (evaluating 'd.map')on every page that makes API calls (Settings, Dashboard, etc.).Root Cause
Fix
Only run the
sedreplacement when the env vars are actually set (non-empty). When not set, the build-time defaults remain intact and work correctly with the existingnginx.confproxy_passtoserver:5001.Also added:
set -efor fail-fast behavior[ -f "$file" ]) to avoid errors on empty globTesting
Docker Compose (default — no runtime env vars):
Kubernetes / custom deployment (with runtime env vars):
docker run -e REACT_APP_API_URL=https://myhost.com/api \ -e REACT_APP_WEBSOCKET_URL=wss://myhost.com \ -p 8080:80 runwatch-client:fix # URLs replaced at startup ✅ # API calls route to custom host ✅Fixes regression from f899d10.