diff --git a/config.json b/config.json index 55df760..a2dd577 100644 --- a/config.json +++ b/config.json @@ -105,5 +105,6 @@ "errorPages": [], "useWebRootServerSideScript": true, "exposeModsInErrorPages": true, - "disableTrailingSlashRedirects": false + "disableTrailingSlashRedirects": false, + "environmentVariables": {} } diff --git a/index.html b/index.html index 20c158e..1fdb812 100644 --- a/index.html +++ b/index.html @@ -131,7 +131,8 @@   "errorPages": [],
  "useWebRootServerSideScript": true,
  "exposeModsInErrorPages": true,
-   "disableTrailingSlashRedirects": false
+   "disableTrailingSlashRedirects": false,
+   "environmentVariables": {}
} diff --git a/svr.js b/svr.js index 764adc3..ddf1023 100644 --- a/svr.js +++ b/svr.js @@ -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;