diff options
Diffstat (limited to 'lib/config/index.js')
-rw-r--r-- | lib/config/index.js | 49 |
1 files changed, 30 insertions, 19 deletions
diff --git a/lib/config/index.js b/lib/config/index.js index f96684ea..c1005b0b 100644 --- a/lib/config/index.js +++ b/lib/config/index.js @@ -8,22 +8,30 @@ const {merge} = require('lodash') const deepFreeze = require('deep-freeze') const {Environment, Permission} = require('./enum') const logger = require('../logger') +const {getGitCommit, getGitHubURL} = require('./utils') -const appRootPath = path.join(__dirname, '../../') +const appRootPath = path.resolve(__dirname, '../../') const env = process.env.NODE_ENV || Environment.development const debugConfig = { debug: (env === Environment.development) } // Get version string from package.json -const {version} = require(path.join(appRootPath, 'package.json')) +const {version, repository} = require(path.join(appRootPath, 'package.json')) + +const commitID = getGitCommit(appRootPath) +const sourceURL = getGitHubURL(repository.url, commitID || version) +const fullversion = commitID ? `${version}-${commitID}` : version const packageConfig = { version: version, - minimumCompatibleVersion: '0.5.0' + minimumCompatibleVersion: '0.5.0', + fullversion: fullversion, + sourceURL: sourceURL } -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') @@ -37,6 +45,12 @@ merge(config, require('./hackmdEnvironment')) merge(config, require('./environment')) merge(config, require('./dockerSecret')) +if (['debug', 'verbose', 'info', 'warn', 'error'].includes(config.loglevel)) { + logger.level = config.loglevel +} else { + logger.error('Selected loglevel %s doesn\'t exist, using default level \'debug\'. Available options: debug, verbose, info, warn, error', config.loglevel) +} + // load LDAP CA if (config.ldap.tlsca) { let ca = config.ldap.tlsca.split(',') @@ -95,6 +109,7 @@ config.isGoogleEnable = config.google.clientID && config.google.clientSecret config.isDropboxEnable = config.dropbox.clientID && config.dropbox.clientSecret config.isTwitterEnable = config.twitter.consumerKey && config.twitter.consumerSecret config.isEmailEnable = config.email +config.isOpenIDEnable = config.openID config.isGitHubEnable = config.github.clientID && config.github.clientSecret config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret @@ -104,10 +119,12 @@ config.isOAuth2Enable = config.oauth2.clientID && config.oauth2.clientSecret config.isPDFExportEnable = config.allowPDFExport // Check gitlab api version -if (config.gitlab.version !== 'v4' && config.gitlab.version !== 'v3') { +if (config.gitlab && config.gitlab.version !== 'v4' && config.gitlab.version !== 'v3') { logger.warn('config.js contains wrong version (' + config.gitlab.version + ') for gitlab api; it should be \'v3\' or \'v4\'. Defaulting to v4') config.gitlab.version = 'v4' } +// If gitlab scope is api, enable snippets Export/import +config.isGitlabSnippetsEnable = (!config.gitlab.scope || config.gitlab.scope === 'api') // Only update i18n files in development setups config.updateI18nFiles = (env === Environment.development) @@ -173,20 +190,14 @@ 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.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.uploadsPath = path.resolve(appRootPath, config.uploadsPath) // make config readonly config = deepFreeze(config) |