chore(api): use .env.production on server, .env for local dev only

Load production env without .env override; sync-api-env targets .env.production; PM2 NODE_ENV=production; Prisma uses with-api-env.cjs on deploy.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-07 23:33:34 +08:00
parent c6af8480a4
commit 6dc051f26d
13 changed files with 68 additions and 41 deletions
+2 -8
View File
@@ -50,24 +50,18 @@ fi
log "PULL $LOCAL_SHA -> $REMOTE_SHA"
# 保留生产密钥,避免 reset 覆盖
# 保留服务器生产密钥,避免 reset 覆盖
ENV_BACKUP="$(mktemp)"
API_ENV_BACKUP="$(mktemp)"
API_ENV_DEV_BACKUP="$(mktemp)"
API_ENV_PROD_BACKUP="$(mktemp)"
cp "$ENV_FILE" "$ENV_BACKUP" 2>/dev/null || true
cp "$APP_ROOT/server/dukang-api/.env" "$API_ENV_BACKUP" 2>/dev/null || true
cp "$APP_ROOT/server/dukang-api/.env.development" "$API_ENV_DEV_BACKUP" 2>/dev/null || true
cp "$APP_ROOT/server/dukang-api/.env.production" "$API_ENV_PROD_BACKUP" 2>/dev/null || true
git checkout "$GIT_BRANCH"
git reset --hard "$GIT_REMOTE/$GIT_BRANCH"
cp "$ENV_BACKUP" "$ENV_FILE" 2>/dev/null || true
cp "$API_ENV_BACKUP" "$APP_ROOT/server/dukang-api/.env" 2>/dev/null || true
cp "$API_ENV_DEV_BACKUP" "$APP_ROOT/server/dukang-api/.env.development" 2>/dev/null || true
cp "$API_ENV_PROD_BACKUP" "$APP_ROOT/server/dukang-api/.env.production" 2>/dev/null || true
rm -f "$ENV_BACKUP" "$API_ENV_BACKUP" "$API_ENV_DEV_BACKUP" "$API_ENV_PROD_BACKUP"
rm -f "$ENV_BACKUP" "$API_ENV_PROD_BACKUP"
sed -i 's/\r$//' "$ENV_FILE" 2>/dev/null || true
# 修复 Windows 换行