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
@@ -0,0 +1,30 @@
import { config } from 'dotenv';
import { spawnSync } from 'child_process';
import { existsSync } from 'fs';
import { resolve } from 'path';
const apiRoot = resolve(__dirname, '..');
const envFile = process.env.DUKANG_ENV_FILE ?? '.env.production';
const envPath = resolve(apiRoot, envFile);
if (!existsSync(envPath)) {
console.error(`[with-api-env] 未找到 ${envPath}`);
process.exit(1);
}
config({ path: envPath, override: true });
const args = process.argv.slice(2);
if (args.length === 0) {
console.error('用法: node scripts/with-api-env.cjs <command> [args...]');
process.exit(1);
}
const result = spawnSync(args[0], args.slice(1), {
cwd: apiRoot,
stdio: 'inherit',
env: process.env,
shell: true,
});
process.exit(result.status ?? 1);