From 5aadc3d3a1f0974bd8ba53b2745e68f92b9dcdb4 Mon Sep 17 00:00:00 2001 From: Ivan Fontosh Date: Sun, 28 Jun 2026 12:53:08 +0800 Subject: [PATCH] Fix server startup when launched via PM2. Use a more reliable main-module check so the HTTP listener starts under process managers. Co-authored-by: Cursor --- src/server.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server.mjs b/src/server.mjs index 4e9ed82..21e4d0d 100644 --- a/src/server.mjs +++ b/src/server.mjs @@ -2,7 +2,7 @@ import { randomUUID } from 'node:crypto'; import fs from 'node:fs'; import http from 'node:http'; import path from 'node:path'; -import { fileURLToPath, pathToFileURL } from 'node:url'; +import { fileURLToPath } from 'node:url'; import { signPayload } from '../lib/signPayload.mjs'; @@ -190,8 +190,10 @@ export function createServer(options = {}) { }); } +const entryPath = process.argv[1] ? path.resolve(process.argv[1]) : ''; const isMain = - process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url; + entryPath !== '' && + (fileURLToPath(import.meta.url) === entryPath || entryPath.endsWith(`${path.sep}server.mjs`)); if (isMain) { const privateKeyPem = process.env.LICENSE_PRIVATE_KEY_PEM;