-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecosystem.config.cjs
More file actions
70 lines (68 loc) · 2.29 KB
/
Copy pathecosystem.config.cjs
File metadata and controls
70 lines (68 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// PM2 processes for MSK Forms (concept §23).
// Deploy: `pm2 reload ecosystem.config.cjs --update-env`
//
// The standalone Next.js server (and the bot/realtime services) do NOT load
// `.env` themselves in production — Next only reads .env at build/dev time.
// So we load `/opt/msk-forms/.env` here and pass it through to every app's
// env. Node 22's process.loadEnvFile populates process.env without any extra
// dependency.
try {
process.loadEnvFile(`${__dirname}/.env`);
} catch {
// No .env present (e.g. local checkout) — rely on the ambient environment.
}
// Snapshot the resolved environment so every app inherits the secrets.
const baseEnv = { ...process.env };
module.exports = {
apps: [
{
name: "msk-forms-web",
cwd: "./apps/web",
script: ".next/standalone/apps/web/server.js",
env: {
...baseEnv,
NODE_ENV: "production",
// Must match the Apache reverse-proxy target (forms.msk-scripts.de -> 3008).
PORT: "3008",
// Bind to loopback only — reachable solely via the Apache reverse proxy.
HOSTNAME: "127.0.0.1",
},
instances: 1,
exec_mode: "cluster",
max_memory_restart: "512M",
},
{
// Run the bot's TypeScript directly via tsx: it imports @msk-forms/db,
// a bundler-only (source) package that can't be consumed from a plain
// `node dist` build. tsx resolves it the same way Next does. tsx is a
// (dev)dependency installed by the non-prod `pnpm install` on deploy.
name: "msk-forms-bot",
cwd: "./apps/bot",
script: "src/index.ts",
interpreter: "node",
interpreter_args: "--import tsx",
// A gateway bot holds a single connection — fork, never cluster. Cluster
// mode also doesn't play well with the --import tsx interpreter.
exec_mode: "fork",
env: {
...baseEnv,
NODE_ENV: "production",
},
instances: 1,
max_memory_restart: "256M",
},
{
name: "msk-forms-realtime",
cwd: "./apps/realtime",
script: "dist/index.js",
env: {
...baseEnv,
NODE_ENV: "production",
// 3100 is taken on the server; 3009 sits next to the web app (3008).
REALTIME_PORT: "3009",
},
instances: 1,
max_memory_restart: "256M",
},
],
};