forked from svrjs/svrjs
feat: add options related to disabling configuration file saving, and use them in the "dev" script
This commit is contained in:
parent
8e1ea9e5bc
commit
5a0ea4007e
4 changed files with 81 additions and 64 deletions
|
@ -59,5 +59,6 @@
|
|||
"disableTrailingSlashRedirects": false,
|
||||
"environmentVariables": {},
|
||||
"allowDoubleSlashes": false,
|
||||
"optOutOfStatisticsServer": false
|
||||
"optOutOfStatisticsServer": false,
|
||||
"disableConfigurationSaving": false
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
"build": "npm run clean && NODE_ENV=production node esbuild.config.js",
|
||||
"cz": "cz",
|
||||
"clean": "rimraf dist && rimraf out && rimraf generatedAssets",
|
||||
"dev": "npm run clean && concurrently \"NODE_ENV=development node esbuild.config.js\" \"wait-on dist/svr.js && nodemon dist/svr.js --stdout-notty\"",
|
||||
"dev": "npm run clean && concurrently \"NODE_ENV=development node esbuild.config.js\" \"wait-on dist/svr.js && nodemon dist/svr.js --stdout-notty --no-save-config\"",
|
||||
"lint": "eslint --no-error-on-unmatched-pattern src/**/*.js src/*.js tests/**/*.test.js tests/**/*.js tests/*.test.js tests/*.js",
|
||||
"lint:fix": "npm run lint -- --fix",
|
||||
"prepare": "husky",
|
||||
|
|
19
src/index.js
19
src/index.js
|
@ -117,7 +117,7 @@ if (process.versions) process.versions.svrjs = version; // Inject SVR.JS into pr
|
|||
function printUsage() {
|
||||
console.log(`${name} usage:`);
|
||||
console.log(
|
||||
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [--stdout-notty] [-v] [--version]"
|
||||
"node svr.js [-h] [--help] [-?] [/h] [/?] [--secure] [--reset] [--clean] [--disable-mods] [--single-threaded] [--stdout-notty] [--no-save-config] [-v] [--version]"
|
||||
);
|
||||
console.log("-h -? /h /? --help -- Displays help");
|
||||
console.log("--clean -- Cleans up files created by " + name);
|
||||
|
@ -130,6 +130,7 @@ function printUsage() {
|
|||
console.log(
|
||||
"--stdout-notty -- Enable stdout even when stdout is not a TTY. May decrease the performace"
|
||||
);
|
||||
console.log("--no-save-config -- Don't save configuration file");
|
||||
console.log("-v --version -- Display server version");
|
||||
}
|
||||
|
||||
|
@ -137,6 +138,7 @@ let exiting = false;
|
|||
let forceSecure = false;
|
||||
let disableMods = false;
|
||||
let stdoutNoTTY = false;
|
||||
let noSaveConfig = false;
|
||||
|
||||
// Handle command line arguments
|
||||
const args = process.argv;
|
||||
|
@ -190,6 +192,8 @@ for (
|
|||
process.singleThreaded = true;
|
||||
} else if (args[i] == "--stdout-notty") {
|
||||
stdoutNoTTY = true;
|
||||
} else if (args[i] == "--no-save-config") {
|
||||
noSaveConfig = true;
|
||||
} else {
|
||||
console.log(`Unrecognized argument: ${args[i]}`);
|
||||
printUsage();
|
||||
|
@ -335,6 +339,11 @@ if (process.serverConfig.allowPostfixDoubleSlashes === undefined)
|
|||
process.serverConfig.allowPostfixDoubleSlashes = false;
|
||||
if (process.serverConfig.optOutOfStatisticsServer === undefined)
|
||||
process.serverConfig.optOutOfStatisticsServer = false;
|
||||
if (process.serverConfig.disableConfigurationSaving === undefined)
|
||||
process.serverConfig.disableConfigurationSaving = false;
|
||||
|
||||
// Don't save configuration if disableConfigurationSaving option is set to true
|
||||
if (process.serverConfig.disableConfigurationSaving) noSaveConfig = true;
|
||||
|
||||
// Compatiblity for very old SVR.JS mods
|
||||
process.serverConfig.version = version;
|
||||
|
@ -1692,6 +1701,8 @@ function saveConfig() {
|
|||
configJSONobj.allowDoubleSlashes = false;
|
||||
if (configJSONobj.optOutOfStatisticsServer === undefined)
|
||||
configJSONobj.optOutOfStatisticsServer = false;
|
||||
if (configJSONobj.disableConfigurationSaving === undefined)
|
||||
configJSONobj.disableConfigurationSaving = false;
|
||||
|
||||
fs.writeFileSync(
|
||||
process.dirname + "/config.json",
|
||||
|
@ -1984,6 +1995,7 @@ function start(init) {
|
|||
let workersToFork = 1;
|
||||
|
||||
if (cluster.isPrimary === undefined) {
|
||||
if (!noSaveConfig) {
|
||||
setInterval(() => {
|
||||
try {
|
||||
saveConfig();
|
||||
|
@ -1992,7 +2004,9 @@ function start(init) {
|
|||
throw new Error(err);
|
||||
}
|
||||
}, 300000);
|
||||
}
|
||||
} else if (cluster.isPrimary) {
|
||||
if (!noSaveConfig) {
|
||||
setInterval(() => {
|
||||
let allWorkers = Object.keys(cluster.workers);
|
||||
let goodWorkers = [];
|
||||
|
@ -2048,6 +2062,7 @@ function start(init) {
|
|||
});
|
||||
}, 300000);
|
||||
}
|
||||
}
|
||||
|
||||
if (!cluster.isPrimary && cluster.isPrimary !== undefined) {
|
||||
process.on("message", (line) => {
|
||||
|
@ -2435,7 +2450,7 @@ if (cluster.isPrimary || cluster.isPrimary === undefined) {
|
|||
|
||||
process.on("exit", (code) => {
|
||||
try {
|
||||
if (!configJSONRErr && !configJSONPErr) {
|
||||
if (!configJSONRErr && !configJSONPErr && !noSaveConfig) {
|
||||
saveConfig();
|
||||
}
|
||||
} catch (err) {
|
||||
|
|
|
@ -73,7 +73,8 @@
|
|||
"disableTrailingSlashRedirects": false,
|
||||
"environmentVariables": {},
|
||||
"allowDoubleSlashes": false,
|
||||
"optOutOfStatisticsServer": false
|
||||
"optOutOfStatisticsServer": false,
|
||||
"disableConfigurationSaving": false
|
||||
}</pre>
|
||||
</code>
|
||||
<p>Changes:</p>
|
||||
|
|
Reference in a new issue