Files
beenvoice/apps/mobile/lib/config.ts
T
soconnor d057ba208d Add 'apps/mobile/' from commit '5fa30f365f21531094cd4d2045042bb4f1370ac3'
git-subtree-dir: apps/mobile
git-subtree-mainline: 86f8987dff
git-subtree-split: 5fa30f365f
2026-08-16 21:42:59 -04:00

34 lines
1000 B
TypeScript

import Constants from "expo-constants";
/** Production API used by default (App Store review + production builds). */
export const DEFAULT_API_URL = "https://beenvoice.app";
export const OFFICIAL_SERVER_HOST = new URL(DEFAULT_API_URL).host;
export const OFFICIAL_SERVER_PLACEHOLDER = `${OFFICIAL_SERVER_HOST} or localhost:3000`;
export function invalidServerUrlMessage(): string {
return `Enter a valid server URL (e.g. ${OFFICIAL_SERVER_PLACEHOLDER})`;
}
let runtimeOverride: string | null = null;
export function setRuntimeApiUrl(url: string | null) {
runtimeOverride = url?.replace(/\/$/, "") ?? null;
}
export function getApiUrl() {
if (runtimeOverride) return runtimeOverride;
const fromEnv = process.env.EXPO_PUBLIC_API_URL?.trim();
if (fromEnv) return fromEnv.replace(/\/$/, "");
const hostUri = Constants.expoConfig?.hostUri;
if (hostUri && __DEV__) {
const host = hostUri.split(":")[0];
if (host) return `http://${host}:3000`;
}
return DEFAULT_API_URL;
}