From b36a301e035c836e991c79ae73ce843c62814432 Mon Sep 17 00:00:00 2001 From: Dorian Niemiec Date: Sun, 25 Aug 2024 19:20:15 +0200 Subject: [PATCH] Add close and open commands. --- src/index.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 88a483a..89655cd 100644 --- a/src/index.js +++ b/src/index.js @@ -944,9 +944,60 @@ if (process.serverConfig.secure) { } } -// TODO: close, open, stop, restart commands +// TODO: stop, restart commands // Base commands let commands = { + close: function () { + try { + server.close(); + if ( + process.serverConfig.secure && + !process.serverConfig.disableNonEncryptedServer + ) { + server2.close(); + } + log("Server closed."); + if (cluster.isPrimary !== undefined) process.send("\x12CLOSE"); + } catch (err) { + log("Cannot close server! Reason: " + err.message); + } + }, + open: function () { + try { + if ( + typeof (process.serverConfig.secure + ? process.serverConfig.sport + : process.serverConfig.port) == "number" && + (process.serverConfig.secure ? sListenAddress : listenAddress) + ) { + server.listen( + process.serverConfig.secure + ? process.serverConfig.sport + : process.serverConfig.port, + process.serverConfig.secure ? sListenAddress : listenAddress, + ); + } else { + server.listen( + process.serverConfig.secure + ? process.serverConfig.sport + : process.serverConfig.port, + ); + } + if ( + process.serverConfig.secure && + !process.serverConfig.disableNonEncryptedServer + ) { + if (typeof process.serverConfig.port == "number" && listenAddress) { + server2.listen(process.serverConfig.port, listenAddress); + } else { + server2.listen(process.serverConfig.port); + } + } + log("Server opened."); + } catch (err) { + log("Cannot open server! Reason: " + err.message); + } + }, help: (args, log) => { log("Server commands:\n" + Object.keys(commands).join(" ")); },