Fix PM2 startup and harden server entry detection.

Use a bash launch script for production and pathToFileURL-based main-module checks so sourcing.simosen.cn listens reliably under PM2.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-15 00:55:21 +08:00
parent e9939ef9dc
commit 3cace7ab42
3 changed files with 17 additions and 4 deletions
+2 -2
View File
@@ -3,8 +3,8 @@ module.exports = {
{ {
name: "product-sourcing", name: "product-sourcing",
cwd: "/www/wwwroot/sourcing.simosen.cn/app", cwd: "/www/wwwroot/sourcing.simosen.cn/app",
script: "src/server.js", script: "deploy/start.sh",
interpreter: "node", interpreter: "/bin/bash",
env: { env: {
NODE_ENV: "production", NODE_ENV: "production",
PORT: "9477", PORT: "9477",
+4
View File
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
exec /root/.nvm/versions/node/v20.20.2/bin/node src/server.js
+11 -2
View File
@@ -2,7 +2,7 @@ import { createReadStream } from "node:fs";
import { readdir, readFile, stat } from "node:fs/promises"; import { readdir, readFile, stat } from "node:fs/promises";
import { createServer as createHttpServer } from "node:http"; import { createServer as createHttpServer } from "node:http";
import { extname, join, normalize, resolve } from "node:path"; import { extname, join, normalize, resolve } from "node:path";
import { fileURLToPath } from "node:url"; import { fileURLToPath, pathToFileURL } from "node:url";
import { buildDashboard, buildStyleGroups, toCsv } from "./core.js"; import { buildDashboard, buildStyleGroups, toCsv } from "./core.js";
import { JsonStore } from "./store.js"; import { JsonStore } from "./store.js";
@@ -867,7 +867,16 @@ function crc32(buffer) {
return (crc ^ 0xffffffff) >>> 0; return (crc ^ 0xffffffff) >>> 0;
} }
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) { function isMainModule() {
if (!process.argv[1]) return false;
try {
return import.meta.url === pathToFileURL(resolve(process.argv[1])).href;
} catch {
return false;
}
}
if (isMainModule()) {
try { try {
await readFile(join(DEFAULT_PUBLIC_DIR, "index.html")); await readFile(join(DEFAULT_PUBLIC_DIR, "index.html"));
} catch { } catch {