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 <cursoragent@cursor.com>
This commit is contained in:
Ivan Fontosh
2026-06-28 12:53:08 +08:00
parent a6a0e8adf8
commit 5aadc3d3a1
+4 -2
View File
@@ -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;