From 535291a91ac814a9461cf01579d01405fb0c585f Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Mon, 7 Mar 2022 14:14:32 +1300 Subject: [PATCH] Add `local_environments` to configuration files Add `local` parameter to global `config` object to avoid repeating tests JWT key `secret` only added to global object `config` when local installation detected --- client/homebrew/navbar/account.navitem.jsx | 4 +--- config/default.json | 3 ++- server/app.js | 11 +++++++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/homebrew/navbar/account.navitem.jsx b/client/homebrew/navbar/account.navitem.jsx index e0fa555da..9627107a5 100644 --- a/client/homebrew/navbar/account.navitem.jsx +++ b/client/homebrew/navbar/account.navitem.jsx @@ -43,8 +43,6 @@ const Account = createClass({ }, render : function(){ - const localEnvironments = ['local', 'docker']; - // Logged in if(global.account){ return @@ -75,7 +73,7 @@ const Account = createClass({ // Logged out // LOCAL ONLY - if(localEnvironments.includes(global.config.environment)) { + if(global.config.local) { return login ; diff --git a/config/default.json b/config/default.json index f74ce3b8e..f630b5b0f 100644 --- a/config/default.json +++ b/config/default.json @@ -3,5 +3,6 @@ "naturalcrit_url" : "local.naturalcrit.com:8010", "secret" : "secret", "web_port" : 8000, - "enable_v3" : true + "enable_v3" : true, + "local_environments" : ["docker", "local"] } diff --git a/server/app.js b/server/app.js index fb1e4e64b..87711433f 100644 --- a/server/app.js +++ b/server/app.js @@ -262,9 +262,16 @@ app.get('/print/:id', asyncHandler(async (req, res, next)=>{ //Render the page const templateFn = require('./../client/template.js'); app.use((req, res)=>{ + // Create configuration object const configuration = { - environment : config.get('node_env'), - secret : config.get('secret') + local : false, + environment : config.get('node_env') + }; + // Add local only items to configuration object + const localEnvironments = config.get('local_environments'); + if(localEnvironments.includes(configuration.environment)){ + configuration.local = true; + configuration.secret = config.get('secret'); }; const props = { version : require('./../package.json').version,