Repository navigation
feat(mobile): 根据 __DEV__ 自动切换 API 地址 - #57
Merged
Merged
Conversation
抽出 lib/config.ts,用 __DEV__ 在 EXPO_PUBLIC_API_URL_DEV 和 EXPO_PUBLIC_API_URL 之间切换,缺失时启动即抛错。 .env 从此一次写死,不再手动来回改。 Co-Authored-By: Claude <noreply@anthropic.com>
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.
Summary
apps/mobile/lib/config.ts:用__DEV__在EXPO_PUBLIC_API_URL_DEV(开发)与EXPO_PUBLIC_API_URL(生产)之间切换,变量缺失时启动即抛错apps/mobile/lib/api.ts、apps/mobile/lib/auth.ts改为从./config导入API_BASEapps/mobile/.env.example补齐双变量,并加注释说明真机调试不能用localhost动机
之前本地开发和线上发布共用
EXPO_PUBLIC_API_URL,每次切换环境都要改.env,容易忘改提交。Metro 会把__DEV__和process.env.EXPO_PUBLIC_*内联为字面常量,所以运行时零开销。Test plan
cp apps/mobile/.env.example apps/mobile/.env并把EXPO_PUBLIC_API_URL_DEV改为开发机局域网 IPpnpm dev启动 Expo,真机登录 / 拉交易列表,确认走 DEV URL.env里的EXPO_PUBLIC_API_URL_DEV,确认启动时抛出"API_BASE 未配置"错误pnpm --filter mobile exec expo start --no-dev --minify启动,真机/模拟器连上确认走生产 URL(119.45.41.158)Co-Authored-By: Claude noreply@anthropic.com