rex-server
Version:
Rex Server is a Node.js-based reverse proxy server available as an npm package. It allows you to handle HTTP and HTTPS traffic, route requests to upstream servers, and manage worker processes efficiently. With its CLI interface, Rex makes it easy to confi
71 lines (70 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.rexServerReady = rexServerReady;
exports.workerReady = workerReady;
exports.informMasterAboutEvt = informMasterAboutEvt;
exports.informParentAboutEvt = informParentAboutEvt;
const _types_1 = require("../types/index");
/**
* Informs the master process that the worker process is ready to handle requests.
*
* This function sends an `IPCINFOMessage` to the master process to indicate that the server startup is complete.
* The message includes a "READY" status to notify that the worker is ready to begin handling requests.
*
* @example
* rexServerReady();
*/
function rexServerReady() {
informParentAboutEvt({
type: "info",
name: _types_1.IPCINFOMessgeName.READY,
message: "REX-STARTUP-COMPLETE"
});
}
/**
* Informs the master process that a specific worker is ready.
*
* This function sends an `IPCINFOMessage` to the master process, indicating that a worker has started and is ready
* to handle requests. It includes the worker's ID and a message to notify the master.
*
* @param {Worker} w - The worker process that is ready.
*
* @example
* workerReady(cluster.worker);
*/
function workerReady(w) {
informMasterAboutEvt({
type: "info",
message: `Worker ${w.id} is ready`,
name: _types_1.IPCINFOMessgeName.READY
});
}
/**
* Sends an event message to the master process.
*
* This function sends an event message to the master process (usually in the cluster). The message can be any type
* of event, such as worker readiness or other informational messages, allowing the master process to monitor the
* status of its workers.
*
* @param {T} message - The message to send to the master process. This could contain any relevant event data.
*
* @example
* informMasterAboutEvt({ type: "info", message: "Worker is ready" });
*/
function informMasterAboutEvt(message) {
process.send && process.send(message);
}
/**
* Sends an event message to the parent process (typically the terminal).
*
* This function sends an event message to the parent process (often the terminal or console), typically used for logging
* or error reporting purposes. The message is serialized to JSON format before being sent.
*
* @param {T} message - The message to send to the parent process. This is usually an error or status message.
*
* @example
* informParentAboutEvt({ type: "info", message: "Rex-Setup-Complete" });
*/
function informParentAboutEvt(message) {
console.error(JSON.stringify(message));
}