fix(web): prevent public bundle localhost api fallback

This commit is contained in:
root 2026-05-05 22:04:06 +00:00
parent db29a3f6b9
commit 5ba315fd02
3 changed files with 9 additions and 7 deletions

View File

@ -50,8 +50,9 @@ services:
BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor} BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor}
GITEA_NPM_TOKEN: ${GITEA_NPM_TOKEN:-} GITEA_NPM_TOKEN: ${GITEA_NPM_TOKEN:-}
VITE_PRODUCT_ID: ${VITE_PRODUCT_ID:-invttrdg} VITE_PRODUCT_ID: ${VITE_PRODUCT_ID:-invttrdg}
VITE_PLATFORM_URL: ${VITE_PLATFORM_URL:-https://api.bytelyst.com/platform/api} # Public web builds must use the hosted APIs even if local .env contains dev localhost values.
VITE_TRADING_API_URL: ${VITE_TRADING_API_URL:-https://api.bytelyst.com/invttrdg} VITE_PLATFORM_URL: https://api.bytelyst.com/platform/api
VITE_TRADING_API_URL: https://api.bytelyst.com/invttrdg
VITE_BACKTEST_ENABLED: ${VITE_BACKTEST_ENABLED:-true} VITE_BACKTEST_ENABLED: ${VITE_BACKTEST_ENABLED:-true}
container_name: invttrdg-web container_name: invttrdg-web
ports: ports:

View File

@ -27,7 +27,7 @@ export function getRuntimeEnvironment(surface: ProductSurface): RuntimeEnvironme
readEnv(`${surfacePrefix}PLATFORM_URL`) ?? readEnv(`${surfacePrefix}PLATFORM_URL`) ??
readEnv('VITE_PLATFORM_URL') ?? readEnv('VITE_PLATFORM_URL') ??
readEnv('PLATFORM_API_URL') ?? readEnv('PLATFORM_API_URL') ??
'http://localhost:4003/api'; (surface === 'web' ? 'https://api.bytelyst.com/platform/api' : 'http://localhost:4003/api');
// Web code appends /api/... itself — no /api suffix in the base URL. // Web code appends /api/... itself — no /api suffix in the base URL.
// Mobile code expects /api included and strips it for socket (EXPO_PUBLIC_TRADING_API_URL=http://host:port/api). // Mobile code expects /api included and strips it for socket (EXPO_PUBLIC_TRADING_API_URL=http://host:port/api).
@ -36,7 +36,9 @@ export function getRuntimeEnvironment(surface: ProductSurface): RuntimeEnvironme
readEnv(`${surfacePrefix}TRADING_API_URL`) ?? readEnv(`${surfacePrefix}TRADING_API_URL`) ??
readEnv('VITE_TRADING_API_URL') ?? readEnv('VITE_TRADING_API_URL') ??
readEnv('TRADING_API_URL') ?? readEnv('TRADING_API_URL') ??
`http://localhost:${productConfig.backendPort}`; (surface === 'web'
? 'https://api.bytelyst.com/invttrdg'
: `http://localhost:${productConfig.backendPort}`);
return { return {
productId, productId,
@ -44,4 +46,3 @@ export function getRuntimeEnvironment(surface: ProductSurface): RuntimeEnvironme
tradingApiUrl, tradingApiUrl,
}; };
} }

View File

@ -3,8 +3,8 @@ import { createTradingKillSwitchClient, createTradingWebTelemetry } from '../../
// Read Vite env vars via import.meta.env (not process.env — Vite does not inject those in the browser bundle) // Read Vite env vars via import.meta.env (not process.env — Vite does not inject those in the browser bundle)
export const tradingRuntime = { export const tradingRuntime = {
productId: (import.meta.env.VITE_PRODUCT_ID as string) || 'invttrdg', productId: (import.meta.env.VITE_PRODUCT_ID as string) || 'invttrdg',
platformApiUrl: (import.meta.env.VITE_PLATFORM_URL as string) || 'http://localhost:4003/api', platformApiUrl: (import.meta.env.VITE_PLATFORM_URL as string) || 'https://api.bytelyst.com/platform/api',
tradingApiUrl: (import.meta.env.VITE_TRADING_API_URL as string) || 'http://localhost:4018', tradingApiUrl: (import.meta.env.VITE_TRADING_API_URL as string) || 'https://api.bytelyst.com/invttrdg',
}; };
export const tradingKillSwitchClient = createTradingKillSwitchClient('web'); export const tradingKillSwitchClient = createTradingKillSwitchClient('web');