환경 변수 로더 경로 확장
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
API_BASE_URL=http://localhost:8080
|
||||
API_BASE_URL=http://43.201.34.104:8080
|
||||
TIMEOUT_MS=15000
|
||||
LOG_LEVEL=debug
|
||||
|
||||
|
||||
@@ -33,17 +33,22 @@ class Environment {
|
||||
envName = envFromDefine.toLowerCase();
|
||||
isProduction = envName == 'production';
|
||||
|
||||
final fileName = '.env.$envName';
|
||||
final candidates = ['.env.$envName', 'assets/.env.$envName'];
|
||||
var initialized = false;
|
||||
try {
|
||||
await dotenv.load(fileName: fileName);
|
||||
initialized = true;
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
// 개발 편의를 위해 파일 미존재 시 경고만 출력하고 진행
|
||||
// 실제 배포에서는 파일 존재가 필수다.
|
||||
// ignore: avoid_print
|
||||
print('[Environment] $fileName 로드 실패: $e');
|
||||
|
||||
for (final fileName in candidates) {
|
||||
if (initialized) {
|
||||
break;
|
||||
}
|
||||
try {
|
||||
await dotenv.load(fileName: fileName);
|
||||
initialized = true;
|
||||
} catch (e) {
|
||||
if (kDebugMode) {
|
||||
// 웹 번들 자산(.env.*)까지 순차 시도 후 실패 시에만 기본값으로 폴백한다.
|
||||
// ignore: avoid_print
|
||||
print('[Environment] $fileName 로드 실패: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ flutter:
|
||||
|
||||
assets:
|
||||
- assets/.env.development
|
||||
- assets/.env.production
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
|
||||
Reference in New Issue
Block a user