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