UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

39 lines (38 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.recalcuateId = exports.id = void 0; const cluster = require("cluster"); const config_1 = require("./../../modules/config"); const utils_1 = require("../../modules/utils"); /** * I build this server's ID from the external IP address of this server and pid. */ function determineId() { let id = ""; if (utils_1.utils.argv.title) { id = utils_1.utils.argv.title.toString(); } else if (process.env.ACTIONHERO_TITLE) { id = process.env.ACTIONHERO_TITLE; } else if (process.env.JEST_WORKER_ID) { id = `test-server-${process.env.JEST_WORKER_ID || 0}`; } else if (!config_1.config || !config_1.config.general.id) { let externalIP = utils_1.utils.getExternalIPAddress(); if (!externalIP) { externalIP = "actionhero"; } id = externalIP; // @ts-ignore - we need to load * as for node v16 support if (cluster["isWorker"]) id += `:${process.pid}`; } else { id = config_1.config.general.id; } return id; } exports.id = determineId(); const recalcuateId = () => (exports.id = determineId()); exports.recalcuateId = recalcuateId;