Authored by 徐炜

Merge branch 'feature/customerService' into feature/customerServiceDemo

... ... @@ -82,11 +82,6 @@ app.use((req, res, next) => {
req.session = {};
}
// 获取客服开关,读cache
global.yoho.cache.get('customerServiceSwitch').then(resule => {
res.locals.customerServiceSwitch = resule || false;
}).catch(next);
next();
});
... ... @@ -104,6 +99,7 @@ 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());
... ... @@ -114,7 +110,7 @@ try {
app.use(user());
app.use(seo());
app.use(setPageInfo());
app.use(secretSwitch());
app.use(pageCache());
require('./dispatch')(app);
... ...
... ... @@ -8,16 +8,13 @@
const cache = global.yoho.cache;
const index = (req, res, next) => {
let customerServiceSwitch = req.query.customerServiceSwitch;
const param = req.query['com.yohobuy.customerservice.enabled'];
let status = param === 'true';
if (typeof customerServiceSwitch === 'undefined') {
res.json(false);
return;
}
cache.set('customerServiceSwitch', customerServiceSwitch ? true : false, -1).then(result => {
cache.set('customerServiceSwitch', status, 0).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
... ...
... ... @@ -13,7 +13,7 @@ var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
const rvCtrl = require(`${cRoot}/recent-view`);
const cache = require(`${cRoot}/cache`);
const cache = require(`${cRoot}/secret-switch`);
const uploadCtrl = require(`${cRoot}/upload`);
const erp2goods = require(`${cRoot}/erp2goods`);
const getBanner = require(`${cRoot}/getBanner`);
... ... @@ -25,7 +25,7 @@ router.post('/upload/image', multipartMiddleware, uploadCtrl.uploadImg);
router.get('/erp2goods', erp2goods.find);
router.get('/cache', cache.index); // 设置cache
router.get('/secret-switch', cache.index); // 设置cache
router.get('/getbanner', getBanner.index);
... ...
const logger = global.yoho.logger;
const secretSwitch = () => {
return (req, res, next) => {
req.user = {}; // 全局的用户数据
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
if (!req.session) {
req.session = {};
}
// 获取客服开关,读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;
... ...