Files
FruitServer/docs/plans/INBOX.md
T

66 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# INBOX
## [已处理] K68-A 指定 API_BASE_URL 时跳过地址探测
### 背景
正式包通过 `--dart-define=API_BASE_URL=http://39.162.50.99:8081` 指定接口地址,
但 `AppConfig.probeAndApplyBaseUrl()` 不支持构建期地址:它只按
`127.0.0.1 → 192.168.31.187 → 公网` 探测,探测结果又会覆盖 `apiBaseUrl`。
后果:正式包启动时仍会去探测局域网;若公网暂时不可达,会回落到开发机地址
`192.168.31.187`,正式包里所有请求都指向错误服务器。
### 目标
- `API_BASE_URL` 已指定时,**不再探测**,直接使用该地址。
- 运行时地址(用户在 App 内手动改的服务器)仍保持最高优先级,不被构建期地址覆盖。
- 未指定 `API_BASE_URL` 时,探测逻辑保持现状。
### 实现
1. `lib/core/config/app_config.dart` 的 `probeAndApplyBaseUrl`:
```dart
static Future<void> probeAndApplyBaseUrl({
Future<bool> Function(String baseUrl)? probe,
String? fallbackBaseUrl,
String? compiledOverride, // 仅测试注入用
}) async {
final compiled = compiledOverride ?? compiledBaseUrl;
if (compiled.isNotEmpty) {
// 构建期已指定接口地址:直接使用,避免正式包回落开发机地址
if (_runtimeBaseUrl.isEmpty) applyRuntimeBaseUrl(compiled);
return;
}
// …原有探测逻辑不变
}
```
2. `lib/main.dart` 不改(已 `AppConfig.ready = AppConfig.probeAndApplyBaseUrl()`)。
3. 测试 `test/config/` 补充:
- 传 `compiledOverride` 时:`probe` 回调一次都不会被调用,`AppConfig.apiBaseUrl` 等于该地址
- 已存在运行时地址且传 `compiledOverride` 时:运行时地址不被覆盖
- 不传 `compiledOverride`(默认空)时:探测逻辑与现有测试保持一致
- 测试结束复位运行时地址
### 验收
- 门禁:`dart analyze lib test` 零告警、`flutter test` 全过、`flutter build apk --debug` 成功。
- 复核用正式包构建命令(Trae 负责重打,不需要 Codex 执行):
```
flutter build apk --release --target-platform android-arm,android-arm64 \
--dart-define=API_BASE_URL=http://39.162.50.99:8081
```
### Git
- 从 `develop` 拉 `fix/lock-compiled-base-url`。
- 提交:`fix(config): 指定 API_BASE_URL 时跳过地址探测`,作者 `Zhou Weidong <502333560@qq.com>`。
- `--no-ff` 合回 `develop` 并 push;`FruitServer/docs/plans/PROGRESS.md` 追加 K68-A 留痕。
### 约束
- 全程中文;禁止 `git add -A`;不改探测候选顺序与超时;完成后停住等待验收。