forked from svrjs/svrjs
Add new config.json option - environmentVariables.
This commit is contained in:
parent
1f42691cbc
commit
ae1738166f
3 changed files with 19 additions and 4 deletions
|
@ -105,5 +105,6 @@
|
|||
"errorPages": [],
|
||||
"useWebRootServerSideScript": true,
|
||||
"exposeModsInErrorPages": true,
|
||||
"disableTrailingSlashRedirects": false
|
||||
"disableTrailingSlashRedirects": false,
|
||||
"environmentVariables": {}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,8 @@
|
|||
"errorPages": [],<br/>
|
||||
"useWebRootServerSideScript": true,<br/>
|
||||
"exposeModsInErrorPages": true,<br/>
|
||||
"disableTrailingSlashRedirects": false<br/>
|
||||
"disableTrailingSlashRedirects": false,<br/>
|
||||
"environmentVariables": {}<br/>
|
||||
}
|
||||
</code>
|
||||
</div>
|
||||
|
|
15
svr.js
15
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,6 +5531,7 @@ 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);
|
||||
|
|
Reference in a new issue