1
0
Fork 0
forked from svrjs/svrjs

Add new config.json option - environmentVariables.

This commit is contained in:
Dorian Niemiec 2023-12-03 12:11:15 +01:00
parent 1f42691cbc
commit ae1738166f
3 changed files with 19 additions and 4 deletions

View file

@ -105,5 +105,6 @@
"errorPages": [],
"useWebRootServerSideScript": true,
"exposeModsInErrorPages": true,
"disableTrailingSlashRedirects": false
"disableTrailingSlashRedirects": false,
"environmentVariables": {}
}

View file

@ -131,7 +131,8 @@
&nbsp;&nbsp;"errorPages": [],<br/>
&nbsp;&nbsp;"useWebRootServerSideScript": true,<br/>
&nbsp;&nbsp;"exposeModsInErrorPages": true,<br/>
&nbsp;&nbsp;"disableTrailingSlashRedirects": false<br/>
&nbsp;&nbsp;"disableTrailingSlashRedirects": false,<br/>
&nbsp;&nbsp;"environmentVariables": {}<br/>
}
</code>
</div>

17
svr.js
View file

@ -1102,6 +1102,8 @@ var rewriteDirtyURLs = false;
var errorPages = [];
var useWebRootServerSideScript = true;
var exposeModsInErrorPages = true;
var disableTrailingSlashRedirects = false;
var environmentVariables = {};
// Get properties from config.json
if (configJSON.blacklist != undefined) rawBlackList = configJSON.blacklist;
@ -1153,6 +1155,8 @@ if (configJSON.rewriteDirtyURLs != undefined) rewriteDirtyURLs = configJSON.rewr
if (configJSON.errorPages != undefined) errorPages = configJSON.errorPages;
if (configJSON.useWebRootServerSideScript != undefined) useWebRootServerSideScript = configJSON.useWebRootServerSideScript;
if (configJSON.exposeModsInErrorPages != undefined) exposeModsInErrorPages = configJSON.exposeModsInErrorPages;
if (configJSON.disableTrailingSlashRedirects != undefined) disableTrailingSlashRedirects = configJSON.disableTrailingSlashRedirects;
if (configJSON.environmentVariables != undefined) environmentVariables = configJSON.environmentVariables;
var wwwrootError = null;
try {
@ -1161,6 +1165,14 @@ try {
wwwrootError = err;
}
try {
environmentVariables.forEach(function(value, key) {
process.env[key] = value;
});
} catch(err) {
}
// Compability for older mods
configJSON.version = version;
configJSON.productName = "SVR.JS";
@ -4295,7 +4307,7 @@ if (!cluster.isPrimary) {
// Trailing slash redirection
function redirectTrailingSlashes(callback) {
if (!configJSON.disableTrailingSlashRedirects && href[href.length-1] != "/") {
if (!disableTrailingSlashRedirects && href[href.length-1] != "/") {
fs.stat("." + decodeURIComponent(href), function (err, stats) {
if(err || !stats.isDirectory()) {
try {
@ -5519,7 +5531,8 @@ function saveConfig() {
if (configJSONobj.useWebRootServerSideScript === undefined) configJSONobj.useWebRootServerSideScript = true;
if (configJSONobj.exposeModsInErrorPages === undefined) configJSONobj.exposeModsInErrorPages = true;
if (configJSONobj.disableTrailingSlashRedirects === undefined) configJSONobj.disableTrailingSlashRedirects = false;
if (configJSONobj.environmentVariables === undefined) configJSONobj.environmentVariables = {};
var configString = JSON.stringify(configJSONobj, null, 2) + "\n";
fs.writeFileSync(__dirname + "/config.json", configString);
break;