douyin-archive/pm2.config.cjs

38 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const path = require('path');
const dotenv = require('dotenv');
const instances = Number.parseInt(process.env.WEB_CONCURRENCY ?? '1', 10) || 1;
const { parsed: envFromFile = {} } = dotenv.config({ path: path.join(__dirname, '.env') });
module.exports = {
apps: [
{
name: "DouyinArchive",
script: 'npm',
args: 'run start',
cwd: __dirname,
autorestart: true,
restart_delay: 4000,
kill_timeout: 5000,
instances,
exec_mode: instances > 1 ? 'cluster' : 'fork',
// 注意:不要在生产环境 watch否则 Next.js 写入 .next 会触发重启风暴,导致 Playwright 进程被提前关闭
watch: false,
ignore_watch: ['.next', '.turbo', 'generated', 'node_modules', '.git'],
env: {
// 明确开发环境可选项(如需)
NODE_ENV: process.env.NODE_ENV || 'development',
...envFromFile,
},
env_production: {
// 关键:确保应用进程中的 NODE_ENV=production从而禁用 Next.js 的开发特性
NODE_ENV: 'production',
// 为避免多个实例同时拉起共享浏览器,默认单实例;如需并发,请改为独立浏览器服务
WEB_CONCURRENCY: '1',
...envFromFile,
},
time: true
}
]
};