From ce4476fd4a80cfa9a2397ab57e70955668a58804 Mon Sep 17 00:00:00 2001 From: feie9454 Date: Mon, 6 Oct 2025 08:24:25 +0800 Subject: [PATCH] add pm2 config --- pm2.config.cjs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 pm2.config.cjs diff --git a/pm2.config.cjs b/pm2.config.cjs new file mode 100644 index 0000000..a3bb126 --- /dev/null +++ b/pm2.config.cjs @@ -0,0 +1,39 @@ +/** + * PM2 ecosystem configuration for the consumable temp request API. + * + * This configuration assumes the project runs with Bun so that TypeScript files can be executed directly. + * Adjust the `interpreter` field if you prefer a different runtime (e.g. `node` with `tsx`). + */ + +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: 'sm-server', + script: 'index.ts', + cwd: __dirname, + interpreter: process.env.PM2_INTERPRETER ?? 'bun', + autorestart: true, + restart_delay: 4000, + kill_timeout: 5000, + instances, + exec_mode: instances > 1 ? 'cluster' : 'fork', + watch: process.env.NODE_ENV !== 'production', + ignore_watch: ['generated', 'node_modules', '.git'], + env: { + ...envFromFile, + NODE_ENV: 'development' + }, + env_production: { + ...envFromFile, + NODE_ENV: 'production' + }, + time: true + } + ] +};