2017-10-25 13:49:37 +00:00
|
|
|
|
2017-04-12 17:57:55 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const fs = require('fs')
|
|
|
|
const path = require('path')
|
|
|
|
const {merge} = require('lodash')
|
|
|
|
const deepFreeze = require('deep-freeze')
|
|
|
|
const {Environment, Permission} = require('./enum')
|
|
|
|
|
|
|
|
const appRootPath = path.join(__dirname, '../../')
|
|
|
|
const env = process.env.NODE_ENV || Environment.development
|
|
|
|
const debugConfig = {
|
|
|
|
debug: (env === Environment.development)
|
|
|
|
}
|
|
|
|
|
2018-01-19 12:23:30 +00:00
|
|
|
const {version} = require(path.join(appRootPath, 'package.json'))
|
|
|
|
|
2017-04-12 17:57:55 +00:00
|
|
|
const packageConfig = {
|
2018-01-19 12:23:30 +00:00
|
|
|
version: version,
|
2017-04-12 17:57:55 +00:00
|
|
|
minimumCompatibleVersion: '0.5.0'
|
|
|
|
}
|
|
|
|
|
|
|
|
const configFilePath = path.join(__dirname, '../../config.json')
|
|
|
|
const fileConfig = fs.existsSync(configFilePath) ? require(configFilePath)[env] : undefined
|
|
|
|
|
|
|
|
let config = require('./default')
|
|
|
|
merge(config, require('./defaultSSL'))
|
|
|
|
merge(config, debugConfig)
|
|
|
|
merge(config, packageConfig)
|
|
|
|
merge(config, fileConfig)
|
|
|
|
merge(config, require('./oldEnvironment'))
|
|
|
|
merge(config, require('./environment'))
|
|
|
|
merge(config, require('./dockerSecret'))
|
|
|
|
|
|
|
|
// load LDAP CA
|
|
|
|
if (config.ldap.tlsca) {
|
|
|
|
let ca = config.ldap.tlsca.split(',')
|
|
|
|
let caContent = []
|
|
|
|
for (let i of ca) {
|
2017-06-01 10:58:55 +00:00
|
|
|
if (fs.existsSync(i)) {
|
|
|
|
caContent.push(fs.readFileSync(i, 'utf8'))
|
2017-04-12 17:57:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let tlsOptions = {
|
|
|
|
ca: caContent
|
|
|
|
}
|
|
|
|
config.ldap.tlsOptions = config.ldap.tlsOptions ? Object.assign(config.ldap.tlsOptions, tlsOptions) : tlsOptions
|
|
|
|
}
|
|
|
|
|
|
|
|
// Permission
|
|
|
|
config.permission = Permission
|
2018-01-20 14:05:05 +00:00
|
|
|
if (!config.allowanonymous && !config.allowanonymousedits) {
|
2017-04-12 17:57:55 +00:00
|
|
|
delete config.permission.freely
|
|
|
|
}
|
|
|
|
if (!(config.defaultpermission in config.permission)) {
|
|
|
|
config.defaultpermission = config.permission.editable
|
|
|
|
}
|
|
|
|
|
|
|
|
// cache result, cannot change config in runtime!!!
|
|
|
|
config.isStandardHTTPsPort = (function isStandardHTTPsPort () {
|
|
|
|
return config.usessl && config.port === 443
|
|
|
|
})()
|
|
|
|
config.isStandardHTTPPort = (function isStandardHTTPPort () {
|
|
|
|
return !config.usessl && config.port === 80
|
|
|
|
})()
|
|
|
|
|
|
|
|
// cache serverURL
|
|
|
|
config.serverurl = (function getserverurl () {
|
|
|
|
var url = ''
|
|
|
|
if (config.domain) {
|
|
|
|
var protocol = config.protocolusessl ? 'https://' : 'http://'
|
|
|
|
url = protocol + config.domain
|
|
|
|
if (config.urladdport) {
|
|
|
|
if (!config.isStandardHTTPPort || !config.isStandardHTTPsPort) {
|
|
|
|
url += ':' + config.port
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (config.urlpath) {
|
|
|
|
url += '/' + config.urlpath
|
|
|
|
}
|
|
|
|
return url
|
|
|
|
})()
|
|
|
|
|
|
|
|
config.Environment = Environment
|
|
|
|
|
|
|
|
// auth method
|
|
|
|
config.isFacebookEnable = config.facebook.clientID && config.facebook.clientSecret
|
|
|
|
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.isGitHubEnable = config.github.clientID && config.github.clientSecret
|
|
|
|
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
|
2017-10-29 10:16:40 +00:00
|
|
|
config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret
|
2017-04-12 17:57:55 +00:00
|
|
|
config.isLDAPEnable = config.ldap.url
|
2017-11-28 03:46:58 +00:00
|
|
|
config.isSAMLEnable = config.saml.idpSsoUrl
|
2017-10-25 13:49:37 +00:00
|
|
|
config.isPDFExportEnable = config.allowpdfexport
|
2017-04-12 17:57:55 +00:00
|
|
|
|
2018-01-20 14:08:31 +00:00
|
|
|
// figure out mime types for image uploads
|
|
|
|
switch (config.imageUploadType) {
|
|
|
|
case 'imgur':
|
|
|
|
config.allowedUploadMimeTypes = [
|
|
|
|
'image/jpeg',
|
|
|
|
'image/png',
|
|
|
|
'image/jpg',
|
|
|
|
'image/gif'
|
|
|
|
]
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
config.allowedUploadMimeTypes = [
|
|
|
|
'image/jpeg',
|
|
|
|
'image/png',
|
|
|
|
'image/jpg',
|
|
|
|
'image/gif',
|
|
|
|
'image/svg+xml'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2017-04-12 17:57:55 +00:00
|
|
|
// generate correct path
|
2017-12-22 11:19:19 +00:00
|
|
|
config.sslcapath.forEach(function (capath, i, array) {
|
2017-12-22 11:25:13 +00:00
|
|
|
array[i] = path.resolve(appRootPath, capath)
|
2017-12-22 11:19:19 +00:00
|
|
|
})
|
2017-11-28 13:23:50 +00:00
|
|
|
|
2017-04-12 17:57:55 +00:00
|
|
|
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.hackmdpath = path.join(appRootPath, config.hackmdpath)
|
|
|
|
config.errorpath = path.join(appRootPath, config.errorpath)
|
|
|
|
config.prettypath = path.join(appRootPath, config.prettypath)
|
|
|
|
config.slidepath = path.join(appRootPath, config.slidepath)
|
|
|
|
|
2017-10-25 13:49:37 +00:00
|
|
|
// make config readonly
|
2017-04-12 17:57:55 +00:00
|
|
|
config = deepFreeze(config)
|
|
|
|
|
|
|
|
module.exports = config
|