fix api-server env override order

This commit is contained in:
2026-05-08 14:57:47 +08:00
parent 7e8cc22859
commit 8fd0d1b281
4 changed files with 10 additions and 7 deletions

View File

@@ -8,7 +8,7 @@ const apiServerExePath = resolve(
'server-rs/target/debug/api-server.exe',
);
function loadEnvFile(path, target) {
function loadEnvFile(path, target, override = false) {
if (!existsSync(path)) {
return;
}
@@ -26,7 +26,7 @@ function loadEnvFile(path, target) {
}
const [, key, rawValue] = match;
if (target[key] !== undefined) {
if (!override && target[key] !== undefined) {
continue;
}
@@ -36,8 +36,8 @@ function loadEnvFile(path, target) {
const mergedEnv = { ...process.env };
loadEnvFile(resolve(repoRoot, '.env'), mergedEnv);
loadEnvFile(resolve(repoRoot, '.env.local'), mergedEnv);
loadEnvFile(resolve(repoRoot, '.env.secrets.local'), mergedEnv);
loadEnvFile(resolve(repoRoot, '.env.local'), mergedEnv, true);
loadEnvFile(resolve(repoRoot, '.env.secrets.local'), mergedEnv, true);
mergedEnv.GENARRATIVE_API_HOST = mergedEnv.GENARRATIVE_API_HOST || '127.0.0.1';
mergedEnv.GENARRATIVE_API_PORT = mergedEnv.GENARRATIVE_API_PORT || '3100';