Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Valo-Plex8 * File : scripts/serveur.mjs9 * Module : scripts10 * Repository : https://git.spboucher.ai/valo-plex11 * Project Website : https://www.valo-plex.com12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Service à plusieurs processus : N « next start » derrière un même port (module cluster de Node).44// node scripts-serveur.mjs [--processus 2] [--port 8098] [--hote 0.0.0.0]45import cluster from "node:cluster";46import { createRequire } from "node:module";47import process from "node:process";4849const arg = (nom, defaut) => {50 const i = process.argv.indexOf(`--${nom}`);51 return i > 0 ? process.argv[i + 1] : defaut;52};53const N = Math.max(1, Number(arg("processus", 2)));54const PORT = String(arg("port", "8098"));55const HOTE = String(arg("hote", "127.0.0.1"));5657if (cluster.isPrimary) {58 let arret = false;59 for (let i = 0; i < N; i++) cluster.fork();60 cluster.on("exit", (w, code) => {61 if (arret) return;62 console.error(JSON.stringify({ t: new Date().toISOString(), evt: "processus_relance", pid: w.process.pid, code }));63 cluster.fork();64 });65 const stop = () => {66 arret = true;67 for (const w of Object.values(cluster.workers ?? {})) w?.process.kill("SIGTERM");68 setTimeout(() => process.exit(0), 3000).unref();69 };70 process.on("SIGTERM", stop);71 process.on("SIGINT", stop);72 console.log(`valo-plex : ${N} processus sur ${HOTE}:${PORT}`);73} else {74 const require = createRequire(`${process.cwd()}/`);75 process.argv = [process.argv[0], require.resolve("next/dist/bin/next"), "start", "-H", HOTE, "-p", PORT];76 require("next/dist/bin/next");77}78