fix: start main() under pm2 fork mode (pm_exec_path guard)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Showing 1 changed file with +5 and −1
modified
src/server.mjs
+5 −1
@@ -220,6 +220,10 @@ async function main() { | ||
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | −if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { | |
| 223 | +// Run when invoked directly (node src/server.mjs) or under pm2 fork mode, | |
| 224 | +// where argv[1] is pm2's ProcessContainerFork and pm_exec_path is our script. | |
| 225 | +const invokedDirectly = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href; | |
| 226 | +const underPm2 = (process.env.pm_exec_path ?? '').endsWith('server.mjs'); | |
| 227 | +if (invokedDirectly || underPm2) { | |
| 224 | 228 | main(); |
| 225 | 229 | } |
| 226 | 230 | |