Fix front-end constants generation not getting config properly

This commit is contained in:
Wu Cheng-Han 2017-03-23 20:00:48 +08:00
parent 7e3b74d0da
commit dde6e622a4
3 changed files with 17 additions and 3 deletions

10
app.js
View file

@ -30,15 +30,19 @@ var response = require('./lib/response.js')
var models = require('./lib/models') var models = require('./lib/models')
// generate front-end constants by template // generate front-end constants by template
var configJson = config.raw
var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs') var constpath = path.join(__dirname, './public/js/lib/common/constant.ejs')
var googleApiKey = (fs.existsSync('/run/secrets/google_apiKey') && config.handleDockerSecret('google_apiKey')) || process.env.HMD_GOOGLE_API_KEY || (configJson.google && configJson.google.apiKey) || ''
var googleClientID = (fs.existsSync('/run/secrets/google_clientID') && config.handleDockerSecret('google_clientID')) || process.env.HMD_GOOGLE_CLIENT_ID || (configJson.google && configJson.google.clientID) || ''
var dropboxAppKey = (fs.existsSync('/run/secrets/dropbox_appKey') && config.handleDockerSecret('dropbox_appKey')) || process.env.HMD_DROPBOX_APP_KEY || (configJson.dropbox && configJson.dropbox.appKey) || ''
var data = { var data = {
domain: config.domain, domain: config.domain,
urlpath: config.urlpath, urlpath: config.urlpath,
debug: config.debug, debug: config.debug,
version: config.version, version: config.version,
GOOGLE_API_KEY: config.google ? config.google.GOOGLE_API_KEY : '', GOOGLE_API_KEY: googleApiKey,
GOOGLE_CLIENT_ID: config.google ? config.google.GOOGLE_CLIENT_ID : '', GOOGLE_CLIENT_ID: googleClientID,
DROPBOX_APP_KEY: config.dropbox ? config.dropbox.DROPBOX_APP_KEY : '' DROPBOX_APP_KEY: dropboxAppKey
} }
ejs.renderFile(constpath, data, {}, function (err, str) { ejs.renderFile(constpath, data, {}, function (err, str) {
if (err) throw new Error(err) if (err) throw new Error(err)

View file

@ -101,6 +101,10 @@
"description": "Dropbox API client secret", "description": "Dropbox API client secret",
"required": false "required": false
}, },
"HMD_DROPBOX_APP_KEY": {
"description": "Dropbox app key (for import/export)",
"required": false
},
"HMD_GOOGLE_CLIENTID": { "HMD_GOOGLE_CLIENTID": {
"description": "Google API client id", "description": "Google API client id",
"required": false "required": false
@ -109,6 +113,10 @@
"description": "Google API client secret", "description": "Google API client secret",
"required": false "required": false
}, },
"HMD_GOOGLE_API_KEY": {
"description": "Google API key (for import/export)",
"required": false
},
"HMD_IMGUR_CLIENTID": { "HMD_IMGUR_CLIENTID": {
"description": "Imgur API client id", "description": "Imgur API client id",
"required": false "required": false

View file

@ -170,6 +170,8 @@ var maintenance = true
var cwd = path.join(__dirname, '..') var cwd = path.join(__dirname, '..')
module.exports = { module.exports = {
raw: config,
handleDockerSecret: handleDockerSecret,
version: version, version: version,
minimumCompatibleVersion: minimumCompatibleVersion, minimumCompatibleVersion: minimumCompatibleVersion,
maintenance: maintenance, maintenance: maintenance,