Authored by htoooth

merge

... ... @@ -48,7 +48,7 @@ app.locals.version = pkg.version;
// zookeeper
if (config.zookeeperServer) {
require('yoho-zookeeper')(config.zookeeperServer, 'pc', app.locals.pc = {});
require('yoho-zookeeper')(config.zookeeperServer, 'pc', app.locals.pc = {}, global.yoho.cache);
}
app.set('subdomain offset', 2);
... ... @@ -148,7 +148,6 @@ try {
const errorHanlder = require('./doraemon/middleware/error-handler');
const setPageInfo = require('./doraemon/middleware/set-pageinfo');
const pageCache = require('./doraemon/middleware/page-cache');
const secretSwitch = require('./doraemon/middleware/secret-switch');
// YOHO 前置中间件
app.use(subDomain());
... ... @@ -159,7 +158,6 @@ try {
app.use(user());
app.use(seo());
app.use(setPageInfo());
app.use(secretSwitch());
app.use(pageCache());
require('./dispatch')(app);
... ...
/**
* 设置cache controller
* @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
* @date: 2016/12/21
*/
'use strict';
const cache = global.yoho.cache;
const index = (req, res, next) => {
const param = req.query['com.yohobuy.customerservice.enabled'];
let status = param === 'true';
cache.set('customerServiceSwitch', status, 0).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index
};
... ... @@ -10,12 +10,9 @@ const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const ads = require(`${cRoot}/ads`); // 第三方广告平台对接
const secretSwitch = require(`${cRoot}/secret-switch`);
// Your controller here
router.get('/ads', ads.jump);
router.get('/secret-switch', secretSwitch.index); // 设置cache
module.exports = router;
... ...
const logger = global.yoho.logger;
const secretSwitch = () => {
return (req, res, next) => {
// 获取客服开关,读cache
global.yoho.cache.get('customerServiceSwitch').then(result => {
Object.assign(res.locals, {
customerServiceSwitch: result || false
});
next();
}).catch((err) => {
logger.error(err);
next();
});
};
};
module.exports = secretSwitch;
... ... @@ -189,7 +189,7 @@
</div>
<div class="left">
<span class="iconfont rgbf">&#xe602;</span>
<a href="{{#if customerServiceSwitch}}/service/client{{else}}http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409{{/if}}" target="_blank">
<a href="{{#if @root.pc.clientService.new}}/service/client{{else}}http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409{{/if}}" target="_blank">
<span class="red">便捷</span>
<span class="rgbf">在线客服</span>
</a>
... ...
... ... @@ -61,7 +61,7 @@
"uuid": "^2.0.2",
"yoho-express-session": "^2.0.0",
"yoho-node-lib": "0.2.2",
"yoho-zookeeper": "^1.0.4"
"yoho-zookeeper": "^1.0.6"
},
"devDependencies": {
"autoprefixer": "^6.3.6",
... ...