fix(config): ssl environment configs not parse properly

This commit is contained in:
Raccoon Li 2017-05-08 20:41:38 +08:00
parent 826ad213d6
commit 0c619fee91
3 changed files with 20 additions and 7 deletions

View File

@ -1,15 +1,18 @@
'use strict'
const {toBooleanConfig} = require('./utils')
module.exports = {
domain: process.env.HMD_DOMAIN,
urlpath: process.env.HMD_URL_PATH,
port: process.env.HMD_PORT,
urladdport: process.env.HMD_URL_ADDPORT,
usessl: (process.env.HMD_PROTOCOL_USESSL === 'true'),
usessl: toBooleanConfig(process.env.HMD_USESSL),
protocolusessl: toBooleanConfig(process.env.HMD_PROTOCOL_USESSL),
alloworigin: process.env.HMD_ALLOW_ORIGIN ? process.env.HMD_ALLOW_ORIGIN.split(',') : undefined,
usecdn: (process.env.HMD_USECDN === 'true'),
allowanonymous: (process.env.HMD_ALLOW_ANONYMOUS === 'true'),
allowfreeurl: (process.env.HMD_ALLOW_FREEURL === 'true'),
usecdn: toBooleanConfig(process.env.HMD_USECDN),
allowanonymous: toBooleanConfig(process.env.HMD_ALLOW_ANONYMOUS),
allowfreeurl: toBooleanConfig(process.env.HMD_ALLOW_FREEURL),
defaultpermission: process.env.HMD_DEFAULT_PERMISSION,
dburl: process.env.HMD_DB_URL,
imageUploadType: process.env.HMD_IMAGE_UPLOAD_TYPE,
@ -59,6 +62,6 @@ module.exports = {
searchAttributes: process.env.HMD_LDAP_SEARCHATTRIBUTES,
tlsca: process.env.HMD_LDAP_TLS_CA
},
email: (process.env.HMD_EMAIL === 'true'),
allowemailregister: (process.env.HMD_ALLOW_EMAIL_REGISTER === 'true')
email: toBooleanConfig(process.env.HMD_EMAIL),
allowemailregister: toBooleanConfig(process.env.HMD_ALLOW_EMAIL_REGISTER)
}

View File

@ -1,7 +1,9 @@
'use strict'
const {toBooleanConfig} = require('./utils')
module.exports = {
debug: (process.env.DEBUG === 'true'),
debug: toBooleanConfig(process.env.DEBUG),
dburl: process.env.DATABASE_URL,
urlpath: process.env.URL_PATH,
port: process.env.PORT

8
lib/config/utils.js Normal file
View File

@ -0,0 +1,8 @@
'use strict'
exports.toBooleanConfig = function toBooleanConfig (configValue) {
if (configValue && typeof configValue === 'string') {
return (configValue === 'true')
}
return configValue
}