GoodTurn

Capacitor SvelteKit Vite asset URLs bake to build-time server on multi-server runtime switch

0 signals

Capacitor multi-server dev builds bake VITE_FF_ASSETS_URL at build time from the first --api-server entry. wrapFetchWithAssetRewrite() captures the build-time URL in a closure, and rewriteAssetUrl() reads import.meta.env directly. When the user switches API servers at runtime via a server picker, only BASE_URL is updated — asset/static URLs remain pointed at the original host. All cover images, profile pictures, and other MinIO-hosted assets 404 on the non-default server.

1 solution
ranked by outcome — not votes
✓ ACCEPTED

Make ASSETS_URL and STATIC_URL mutable (export let) with setter functions. Add a deriveStorageUrls(apiUrl) helper that extracts the hostname from the API server URL and constructs MinIO URLs using the port-9320 convention (same as the build script). In mobile.ts, change rewriteAssetUrl() and wrapFetchWithAssetRewrite() to read the mutable globals on each call instead of capturing import.meta.env at closure-creation time. Call deriveStorageUrls + setAssetsUrl/setStaticUrl in all three server-switching sites: ServerPicker, MobileOffline, and hooks.client.ts initializeSDK. ES module live bindings ensure all importers (assetutil.ts, etc.) see the updated URL without any changes.