fix(app): Flutter Web 开发模式默认连接 localhost:3000 API
- app.dart: kDebugMode 下使用 AppConfig.dev (localhost:3000) - dev.mjs: flutter run 传入 --dart-define API_BASE_URL/SSE_BASE_URL
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
// └─ BlocProvider<AuthBloc>
|
// └─ BlocProvider<AuthBloc>
|
||||||
// └─ MaterialApp.router
|
// └─ MaterialApp.router
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
import 'package:flutter/foundation.dart' show kIsWeb, kDebugMode;
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -37,7 +37,8 @@ class NuanjiApp extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
// 创建全局依赖(App 生命周期内单例)
|
// 创建全局依赖(App 生命周期内单例)
|
||||||
final config = AppConfig.fromEnvironment();
|
// 开发模式默认使用 localhost,可通过 --dart-define 覆盖
|
||||||
|
final config = kDebugMode ? AppConfig.dev : AppConfig.fromEnvironment();
|
||||||
final apiClient = ApiClient(baseUrl: config.apiBaseUrl);
|
final apiClient = ApiClient(baseUrl: config.apiBaseUrl);
|
||||||
final tokenStore = createSecureTokenStore();
|
final tokenStore = createSecureTokenStore();
|
||||||
final authRepository = AuthRepository(apiClient: apiClient, tokenStore: tokenStore);
|
final authRepository = AuthRepository(apiClient: apiClient, tokenStore: tokenStore);
|
||||||
|
|||||||
@@ -308,7 +308,7 @@ async function startApp() {
|
|||||||
const appDir = resolve(ROOT, "app");
|
const appDir = resolve(ROOT, "app");
|
||||||
const flutterBin = IS_WIN ? "D:\\flutter\\bin\\flutter.bat" : "flutter";
|
const flutterBin = IS_WIN ? "D:\\flutter\\bin\\flutter.bat" : "flutter";
|
||||||
|
|
||||||
const child = spawn(`${flutterBin} run -d chrome --web-port=${PORTS.app}`, {
|
const child = spawn(`${flutterBin} run -d chrome --web-port=${PORTS.app} --dart-define=API_BASE_URL=http://localhost:${PORTS.backend}/api/v1 --dart-define=SSE_BASE_URL=http://localhost:${PORTS.backend}/api/v1`, {
|
||||||
cwd: appDir,
|
cwd: appDir,
|
||||||
shell: true,
|
shell: true,
|
||||||
stdio: "pipe",
|
stdio: "pipe",
|
||||||
|
|||||||
Reference in New Issue
Block a user