Context
Follow-up from PR #5414 (self-hosted server flavour). The admin resolves its API/WebSocket URLs by reading process.env at the composition root:
packages/app-admin/src/base/resolveApiUrl.ts → resolveApiUrl(), resolveWebsocketUrl() read process.env.WEBINY_ADMIN_API_URL / WEBINY_ADMIN_WS_API_URL / REACT_APP_WEBSOCKET_URL.
- These values are baked by the
Admin.ApiUrl / Admin.WebsocketsUrl extensions via the EnvVar mechanism (bundler replaces process.env.X with a literal at build time).
This is confined to the composition root (the rest of the app reads EnvConfig via DI), and it's consistent with the long-standing resolveApiUrl pattern — but it still means process.env reads live in app code, which we'd prefer to avoid.
Goal
Move the admin URL config onto the existing DI BuildParams mechanism (the one FeatureFlags uses via AdminBuildParam → BuildParams.get(key)), so no process.env is read in app code.
Sketch
- Change
Admin.ApiUrl + Admin.WebsocketsUrl extensions to emit AdminBuildParam (DI) instead of EnvVar.
- Read values via
BuildParams.get(...) (DI) at the composition root, feeding EnvConfig as today.
- Update every current reader of the env vars:
resolveApiUrl / resolveGraphqlUrl / resolveWebsocketUrl
- the
appConfig.getKey("API_URL", process.env.WEBINY_ADMIN_API_URL) call sites (graphql-playground, headless-cms api-info, sdk-playground)
Why not in #5414
- It's an admin-URL-config-wide change (ApiUrl too, not just WebSockets) and touches the AWS flavour's readers — bigger blast radius than the server-flavour WS work.
- Doing WS-only would split the pattern (WS via DI, ApiUrl via env) — worse than the current consistent state.
Note on REACT_APP_WEBSOCKET_URL
On AWS this comes from stack output → env (not an extension), so it likely stays env even after this migration, or needs its own handling. Worth deciding during the work.
Related
Context
Follow-up from PR #5414 (self-hosted server flavour). The admin resolves its API/WebSocket URLs by reading
process.envat the composition root:packages/app-admin/src/base/resolveApiUrl.ts→resolveApiUrl(),resolveWebsocketUrl()readprocess.env.WEBINY_ADMIN_API_URL/WEBINY_ADMIN_WS_API_URL/REACT_APP_WEBSOCKET_URL.Admin.ApiUrl/Admin.WebsocketsUrlextensions via theEnvVarmechanism (bundler replacesprocess.env.Xwith a literal at build time).This is confined to the composition root (the rest of the app reads
EnvConfigvia DI), and it's consistent with the long-standingresolveApiUrlpattern — but it still meansprocess.envreads live in app code, which we'd prefer to avoid.Goal
Move the admin URL config onto the existing DI
BuildParamsmechanism (the oneFeatureFlagsuses viaAdminBuildParam→BuildParams.get(key)), so noprocess.envis read in app code.Sketch
Admin.ApiUrl+Admin.WebsocketsUrlextensions to emitAdminBuildParam(DI) instead ofEnvVar.BuildParams.get(...)(DI) at the composition root, feedingEnvConfigas today.resolveApiUrl/resolveGraphqlUrl/resolveWebsocketUrlappConfig.getKey("API_URL", process.env.WEBINY_ADMIN_API_URL)call sites (graphql-playground, headless-cms api-info, sdk-playground)Why not in #5414
Note on
REACT_APP_WEBSOCKET_URLOn AWS this comes from stack output → env (not an extension), so it likely stays env even after this migration, or needs its own handling. Worth deciding during the work.
Related