From e48852e0e2de4441b5ef84dc9bb16be8ba9c01d8 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Wed, 5 Sep 2018 19:50:46 +0200 Subject: lib/config: add environment variable to set config file Previously it was assumed that `config.json` would be placed in the same directory as the rest of CodiMD without any optional override. This allows to override the path to the `config.json` by setting `CMD_CONFIG_FILE` to the canonical path of the desired config file. Signed-off-by: WilliButz --- lib/config/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/config') diff --git a/lib/config/index.js b/lib/config/index.js index 26f0ae96..76c8bbf1 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -23,7 +23,8 @@ const packageConfig = { minimumCompatibleVersion: '0.5.0' } -const configFilePath = path.join(appRootPath, 'config.json') +const configFilePath = path.resolve(appRootPath, process.env.CMD_CONFIG_FILE || +'config.json') const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined let config = require('./default') -- cgit v1.2.3 From 556783ffad2e26c490c0d9d9520d7ee13a750dbb Mon Sep 17 00:00:00 2001 From: WilliButz Date: Wed, 5 Sep 2018 19:56:41 +0200 Subject: lib/config: use `path.resolve` instead of `path.join` While paths like `tmpPath` could previously be configured, they were all interpreted relative to `appRootPath` because of `path.join`. Now the configurable paths can be canonical and therefore independent of the `appRootPath`. Signed-off-by: WilliButz --- lib/config/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'lib/config') diff --git a/lib/config/index.js b/lib/config/index.js index 76c8bbf1..59db8612 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -174,20 +174,20 @@ config.sslCAPath.forEach(function (capath, i, array) { array[i] = path.resolve(appRootPath, capath) }) -config.sslCertPath = path.join(appRootPath, config.sslCertPath) -config.sslKeyPath = path.join(appRootPath, config.sslKeyPath) -config.dhParamPath = path.join(appRootPath, config.dhParamPath) - -config.tmpPath = path.join(appRootPath, config.tmpPath) -config.defaultNotePath = path.join(appRootPath, config.defaultNotePath) -config.docsPath = path.join(appRootPath, config.docsPath) -config.indexPath = path.join(appRootPath, config.indexPath) -config.codimdPath = path.join(appRootPath, config.codimdPath) -config.errorPath = path.join(appRootPath, config.errorPath) -config.prettyPath = path.join(appRootPath, config.prettyPath) -config.slidePath = path.join(appRootPath, config.slidePath) -config.constantsPath = path.join(appRootPath, config.constantsPath) -config.uploadsPath = path.join(appRootPath, config.uploadsPath) +config.sslCertPath = path.resolve(appRootPath, config.sslCertPath) +config.sslKeyPath = path.resolve(appRootPath, config.sslKeyPath) +config.dhParamPath = path.resolve(appRootPath, config.dhParamPath) + +config.tmpPath = path.resolve(appRootPath, config.tmpPath) +config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath) +config.docsPath = path.resolve(appRootPath, config.docsPath) +config.indexPath = path.resolve(appRootPath, config.indexPath) +config.codimdPath = path.resolve(appRootPath, config.codimdPath) +config.errorPath = path.resolve(appRootPath, config.errorPath) +config.prettyPath = path.resolve(appRootPath, config.prettyPath) +config.slidePath = path.resolve(appRootPath, config.slidePath) +config.constantsPath = path.resolve(appRootPath, config.constantsPath) +config.uploadsPath = path.resolve(appRootPath, config.uploadsPath) // make config readonly config = deepFreeze(config) -- cgit v1.2.3 From bb80bc2292d2841776e8bfd6285f96194d990284 Mon Sep 17 00:00:00 2001 From: Claudius Date: Mon, 10 Sep 2018 22:35:38 +0200 Subject: removing superfluous config parameters for template files Signed-off-by: Claudius --- lib/config/default.js | 7 +------ lib/config/index.js | 10 ++-------- 2 files changed, 3 insertions(+), 14 deletions(-) (limited to 'lib/config') diff --git a/lib/config/default.js b/lib/config/default.js index 6096bce4..5d10ad26 100644 --- a/lib/config/default.js +++ b/lib/config/default.js @@ -38,15 +38,10 @@ module.exports = { sslCAPath: '', dhParamPath: '', // other path + viewPath: './public/views', tmpPath: './tmp', defaultNotePath: './public/default.md', docsPath: './public/docs', - indexPath: './public/views/index.ejs', - codimdPath: './public/views/codimd.ejs', - errorPath: './public/views/error.ejs', - prettyPath: './public/views/pretty.ejs', - slidePath: './public/views/slide.ejs', - constantsPath: './public/js/lib/common/constant.ejs', uploadsPath: './public/uploads', // session sessionName: 'connect.sid', diff --git a/lib/config/index.js b/lib/config/index.js index 59db8612..7d059c5c 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -9,7 +9,7 @@ const deepFreeze = require('deep-freeze') const {Environment, Permission} = require('./enum') const logger = require('../logger') -const appRootPath = path.join(__dirname, '../../') +const appRootPath = path.resolve(__dirname, '../../') const env = process.env.NODE_ENV || Environment.development const debugConfig = { debug: (env === Environment.development) @@ -177,16 +177,10 @@ config.sslCAPath.forEach(function (capath, i, array) { config.sslCertPath = path.resolve(appRootPath, config.sslCertPath) config.sslKeyPath = path.resolve(appRootPath, config.sslKeyPath) config.dhParamPath = path.resolve(appRootPath, config.dhParamPath) - +config.viewPath = path.resolve(appRootPath, config.viewPath) config.tmpPath = path.resolve(appRootPath, config.tmpPath) config.defaultNotePath = path.resolve(appRootPath, config.defaultNotePath) config.docsPath = path.resolve(appRootPath, config.docsPath) -config.indexPath = path.resolve(appRootPath, config.indexPath) -config.codimdPath = path.resolve(appRootPath, config.codimdPath) -config.errorPath = path.resolve(appRootPath, config.errorPath) -config.prettyPath = path.resolve(appRootPath, config.prettyPath) -config.slidePath = path.resolve(appRootPath, config.slidePath) -config.constantsPath = path.resolve(appRootPath, config.constantsPath) config.uploadsPath = path.resolve(appRootPath, config.uploadsPath) // make config readonly -- cgit v1.2.3