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

View File

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