환경 변수 로더 경로 확장
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user