fix(android): read .env.app in capacitor.config.ts so allowNavigation actually ships - #219
Merged
Conversation
… ships
Caught by inspecting the built artifact rather than the build's exit code.
The v1212 AAB built GREEN — every pre-upload check passed — and shipped with
`"android": {}` and NO allowNavigation at all. The fix was in the source and
absent from the thing that would have gone to Play.
Cause: capacitor.config.ts is plain Node. Vite loads `.env.app`; this file does
not. The release script runs `cap sync` in a subshell, so VITE_API_BASE_URL was
undefined at sync time and every value derived from it silently vanished from
the generated native config — with a SUCCESSFUL build either way. Same class as
the documented ".env.app gap" that once produced an APK with no server.url.
Now resolved once, via configuredApiBaseUrl(): process.env first (so CI secrets
still win), then a parse of .env.app. Both the OTA url and the navigation
allowlist derive from that single value, so the host serving the code cannot
drift from the host the app is allowed to navigate to.
Verified in the PACKAGED v1213 artifact:
"server": { ..., "allowNavigation": ["portal.niete.edu.pk"] }
Tests pin the fallback, the env-wins-over-file order, and the single-source
derivation.
Refs: bd-2676
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.
Caught by inspecting the built artifact rather than trusting the build's exit code.
The failure
The v1212 AAB built green — every pre-upload check in
build-niete-aab.shpassed — and shipped with:No
allowNavigation. The entire native half of bd-2676 was in the source and absent from the artifact that would have gone to Play. Uploading it would have burned a versionCode and fixed nothing.Cause
capacitor.config.tsis plain Node. Vite loads.env.app; this file does not. The release script runscap syncin a subshell, soVITE_API_BASE_URLwasundefinedat sync time,allowedNavigationHosts()correctly returned[], and the spread omitted the key — with a SUCCESSFUL build either way.Same class as the documented ".env.app gap" that once produced an APK with no
server.url. Both are invisible unless you open the generated config.Fix
One resolver,
configuredApiBaseUrl():process.envfirst (so CI secrets still win), then a parse of.env.app. Both the OTA url and the navigation allowlist derive from that single value, so the host serving the code cannot drift from the host the app may navigate to.Verified in the packaged v1213 artifact:
Also found — a live contradiction, not fixed here
resolveOtaUrl()returnsurl.origin(bare), butbuild-niete-aab.shrejects a bare origin and demands a/portal/...path (bd-2562). So noNIETE_OTA=1build can currently pass its own guard. I built v1213 withNIETE_OTA=0(bundled assets) to sidestep it. That's a pre-existing repo bug worth its own bead — the skill documents the/portal/loginfix as shipped, but the code returns the bare origin.Tests
Pin the
.env.appfallback, the env-wins-over-file ordering, and the single-source derivation — so this cannot silently regress into another green-but-empty artifact.Refs: bd-2676
🤖 Generated with Claude Code