환경 변수 로더 경로 확장

This commit is contained in:
JiWoong Sul
2025-10-20 15:05:37 +09:00
parent d69e5431ce
commit 3df9aa0bec
3 changed files with 17 additions and 11 deletions

View File

@@ -1,4 +1,4 @@
API_BASE_URL=http://localhost:8080 API_BASE_URL=http://43.201.34.104:8080
TIMEOUT_MS=15000 TIMEOUT_MS=15000
LOG_LEVEL=debug LOG_LEVEL=debug

View File

@@ -33,19 +33,24 @@ class Environment {
envName = envFromDefine.toLowerCase(); envName = envFromDefine.toLowerCase();
isProduction = envName == 'production'; isProduction = envName == 'production';
final fileName = '.env.$envName'; final candidates = ['.env.$envName', 'assets/.env.$envName'];
var initialized = false; var initialized = false;
for (final fileName in candidates) {
if (initialized) {
break;
}
try { try {
await dotenv.load(fileName: fileName); await dotenv.load(fileName: fileName);
initialized = true; initialized = true;
} catch (e) { } catch (e) {
if (kDebugMode) { if (kDebugMode) {
// 개발 편의를 위해 파일 미존재 시 경고만 출력하고 진행 // 웹 번들 자산(.env.*)까지 순차 시도 후 실패 시에만 기본값으로 폴백한다.
// 실제 배포에서는 파일 존재가 필수다.
// ignore: avoid_print // ignore: avoid_print
print('[Environment] $fileName 로드 실패: $e'); print('[Environment] $fileName 로드 실패: $e');
} }
} }
}
if (!initialized) { if (!initialized) {
dotenv.testLoad(); dotenv.testLoad();

View File

@@ -76,6 +76,7 @@ flutter:
assets: assets:
- assets/.env.development - assets/.env.development
- assets/.env.production
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets: