fix(gateway): allow the native WebView origin via CORS (native stuck-offline) #270
Reference in New Issue
Block a user
Delete Branch "feature/native-cors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause (confirmed)
Native emulator bug "starts offline, can't go online." The Capacitor app serves the bundled SPA from
https://localhost, so its Connect calls toerudit-game.ruare cross-origin, and the gateway had no CORS handling — a preflightOPTIONSto the edge returns405with noAccess-Control-Allow-Origin, so the WebView blocks every RPC (incl. the offline→onlineauth.guestreconcile). Verified vs prod:OPTIONS .../scrabble.edge.v1.Gateway/ExecutewithOrigin: https://localhost→ 405, no CORS headers. The native online path was never exercised on-device (D's smoke was airplane-mode only).Fix
withNativeCORSmiddleware (under h2c + abuseGuard, before the mux): answers the preflight and sets CORS headers for the native localhost origins (https/http/capacitor://localhost), reflecting the requested headers, exposingX-Update-Recommended. Web is same-origin and untouched.Deploy note
Must reach PROD (
erudit-game.ru) for the native app to go online — the debug APK targets prod. Merge → development (contour) → master → manual prod deploy. No APK rebuild (server-side; the existing APK works once prod has CORS).Verification
go build/vet ./gateway/...,gofmtclean; newTestWithNativeCORS+ the connectsrv suite green.