Authored by 陈峰

Merge branch 'release/6.7.9' into 'master'

Release/6.7.9



See merge request !387
... ... @@ -77,6 +77,9 @@ app.use((req, res, next) => {
next();
});
app.use(favicon(path.join(__dirname, '/favicon.ico')));
app.use(express.static(path.join(__dirname, 'static')));
// 添加请求上下文
app.use(global.yoho.httpCtx());
... ... @@ -90,8 +93,6 @@ app.use(global.yoho.hbs({
cb: hbsEvent.cb
}));
app.use(favicon(path.join(__dirname, '/favicon.ico')));
app.use(express.static(path.join(__dirname, 'static')));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
... ...
... ... @@ -83,17 +83,17 @@ module.exports = class extends global.yoho.BaseModel {
let saltedToken = sign.makeToken(saltedUid);
let publicToken = saltedToken + salt;
let data = userInfo.data;
let data = userInfo.data || {};
if (!data) {
throw Error('app.passport.profile api error');
if (!userInfo.data) { // 个人信息接口可能限流,即使限流也仍然可以登录
logger.error(`app.passport.profile api error${uid}】`);
}
let encryptionUid = aes.encryptionUid(data.uid);
let encryptionUid = aes.encryptionUid(uid);
let uidCookie =
`${encodeURIComponent(data.profile_name)}::${encryptionUid}::${_.get(data, 'vip_info.title', '')}::${saltedToken}`; // eslint-disable-line
`${encodeURIComponent(data.profile_name || '')}::${encryptionUid}::${_.get(data, 'vip_info.title', '')}::${saltedToken}`; // eslint-disable-line
let isStudent = _.get(data, 'vip_info.is_student') || 0;
res.cookie('_UID', uidCookie, {
... ...
... ... @@ -353,12 +353,13 @@ function getShopInfoAsync(domain, channel, params) {
if (shopId) { // 带id访问
let result = yield this.api.getShopInfo(shopId);
data = result.data;
data = result.data || {};
// 根据店铺ID,未取到店铺信息,跳转至首页
if (result.code !== 200 || _.isEmpty(data)) {
return {redirect: helpers.urlFormat('')};
}
// if (result.code !== 200 || _.isEmpty(data)) {
// return {redirect: helpers.urlFormat('')};
// }
// intro接口可能被限流但页面要展示
let lowerDomain = _.toLower(data.shop_domain);
... ...
... ... @@ -117,8 +117,7 @@ module.exports = {
port: '4444' // influxdb port
},
console: {
close: true,
level: 'info',
level: 'debug',
colorize: 'all',
prettyPrint: true
}
... ... @@ -258,7 +257,46 @@ if (isProduction) {
host: '10.66.4.25',
port: 8086,
db: 'web_monitor',
}
},
loggers: {
infoFile: {
name: 'info',
level: 'info',
filename: '/Data/logs/yohobuy-node/info/info.log',
maxFiles: 1,
tailable: true,
maxsize: Math.pow(1024, 3),
zippedArchive: true,
timestamp() {
return new Date().toString();
}
},
errorFile: {
name: 'error',
level: 'error',
filename: '/Data/logs/yohobuy-node/error/error.log',
maxFiles: 1,
tailable: true,
maxsize: Math.pow(1024, 3),
zippedArchive: true,
handleExceptions: true,
timestamp() {
return new Date().toString();
}
},
udp: { // send by udp
measurement: 'yohobuy_node_log',
level: 'debug', // logger level
host: 'influxdblog.web.yohoops.org', // influxdb host
port: '4444' // influxdb port
},
console: {
close: true,
level: 'info',
colorize: 'all',
prettyPrint: true
}
},
});
} else if (isTest) {
Object.assign(module.exports, {
... ...
... ... @@ -27,70 +27,57 @@ const channelMap = {
const sortMap = {
boys: [
{misort: 11, viewNum: 5},
{misort: 16, viewNum: 5},
{misort: 44, viewNum: 5},
{misort: 26, viewNum: 5},
{misort: 28, viewNum: 5},
{misort: 16, viewNum: 5},
{misort: 21, viewNum: 5},
{misort: 12, viewNum: 5},
{misort: 27, viewNum: 5},
{misort: 45, viewNum: 5},
{misort: 49, viewNum: 5},
{misort: 50, viewNum: 5},
{misort: 60, viewNum: 5},
{misort: 46, viewNum: 5},
{misort: 65, viewNum: 5},
{misort: 59, viewNum: 5},
{misort: 50, viewNum: 5},
{misort: 13, viewNum: 5},
],
girls: [
{misort: 11, viewNum: 4},
{misort: 16, viewNum: 4},
{misort: 44, viewNum: 4},
{misort: 31, viewNum: 4},
{misort: 26, viewNum: 4},
{misort: 28, viewNum: 4},
{misort: 32, viewNum: 4},
{misort: 16, viewNum: 4},
{misort: 21, viewNum: 4},
{misort: 12, viewNum: 4},
{misort: 27, viewNum: 4},
{misort: 45, viewNum: 4},
{misort: 49, viewNum: 4},
{misort: 50, viewNum: 4},
{misort: 60, viewNum: 4},
{misort: 46, viewNum: 4},
{misort: 65, viewNum: 4},
{misort: 59, viewNum: 4},
{misort: 50, viewNum: 4},
{misort: 61, viewNum: 4},
{misort: 14, viewNum: 4},
],
kids: [
{misort: 366, viewNum: 4},
{misort: 396, viewNum: 4},
{misort: 368, viewNum: 4},
{misort: 382, viewNum: 4},
{misort: 371, viewNum: 4},
{misort: 369, viewNum: 4},
{misort: 372, viewNum: 4},
{misort: 396, viewNum: 4},
{misort: 404, viewNum: 4},
{misort: 462, viewNum: 4},
{misort: 400, viewNum: 4},
{misort: 406, viewNum: 4},
{misort: 392, viewNum: 4},
{misort: 448, viewNum: 4},
{misort: 388, viewNum: 4},
{misort: 414, viewNum: 4},
{misort: 386, viewNum: 4},
{misort: 408, viewNum: 4},
],
lifestyle: [
{misort: 1190, viewNum: 5},
{misort: 1194, viewNum: 5},
{misort: 1376, viewNum: 5},
{misort: 1446, viewNum: 5},
{misort: 1202, viewNum: 5},
{misort: 1197, viewNum: 5},
{misort: 1474, viewNum: 5},
{misort: 1194, viewNum: 5},
{misort: 1658, viewNum: 5},
{misort: 1550, viewNum: 5},
{misort: 1736, viewNum: 5},
{misort: 1500, viewNum: 5},
{misort: 1546, viewNum: 5},
{misort: 1550, viewNum: 5},
{misort: 1864, viewNum: 5},
{misort: 1554, viewNum: 5},
{misort: 1736, viewNum: 5},
{misort: 1474, viewNum: 5},
{misort: 1536, viewNum: 5},
{misort: 1598, viewNum: 5},
{misort: 1658, viewNum: 5},
{misort: 1376, viewNum: 5},
]
};
... ...
... ... @@ -10,8 +10,6 @@ const sender = global.yoho.apmSender;
const config = global.yoho.config;
const hostname = require('os').hostname();
const routeEncode = require('./route-encode');
const pathWhiteList = require('./limiter/rules/path-white-list');
const ipWhiteList = require('./limiter/rules/ip-white-list');
const _ = require('lodash');
const limiterIpTime = 3600;
... ... @@ -29,6 +27,60 @@ const forceNoCache = (res) => {
}
};
const _err510 = (req, res, code, err) => {
res.status(code);
if (req.xhr) {
return res.json({
code: 510,
message: err.message || '服务器繁忙请稍后重试!'
});
}
const renderErrPage = (result) => {
result = result || {};
res.render('error/510', {
module: 'common',
page: 'error',
err: err,
title: '服务器繁忙 | Yoho!Buy有货 | 潮流购物逛不停',
headerData: result.headerData
});
};
return req.ctx(headerModel).requestHeaderData(req.yoho.channel).then(renderErrPage).catch(() => {
renderErrPage();
});
};
const _err500 = (req, res, code, err) => {
res.status(code);
if (req.xhr) {
return res.json({
code: 500,
message: err.message || '服务器错误!'
});
}
const renderErrPage = (result) => {
result = result || {};
res.render('error/500', {
module: 'common',
page: 'error',
err: err,
title: '服务器错误 | Yoho!Buy有货 | 潮流购物逛不停',
headerData: result.headerData
});
};
return req.ctx(headerModel).requestHeaderData(req.yoho.channel).then(renderErrPage).catch(() => {
renderErrPage();
});
};
exports.notFound = () => {
return (req, res, next) => {
forceNoCache(res);
... ... @@ -66,9 +118,7 @@ exports.serverError = () => {
const udid = _.get(req, 'cookies.udid', 'yoho');
let errorCode = 500;
err = err || {
code: 500
};
err = err || {};
err.code = parseInt(err.code || err.statusCode, 10) || 500;
... ... @@ -111,74 +161,34 @@ exports.serverError = () => {
} else {
return res.redirect(helpers.urlFormat('/signin.html', {refer: req.fullUrl()}));
}
} else if (err.apiRisk || err.code === 9999991 || err.code === 9999992) {
} else if (err.apiRisk) {
let remoteIp = req.yoho.clientIp;
if (err.apiRisk || (!_.includes(pathWhiteList(), req.path) && !(await ipWhiteList(remoteIp)))) {
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[0];
}
let sessionLimitKey;
let isHuman;
if (err.apiRisk) {
sessionLimitKey = 'apiRiskValidate';
} else {
sessionLimitKey = 'apiLimitValidate';
isHuman = await cache.getAsync(`${config.app}:limiter:api:ishuman:${remoteIp}`);
}
if (!isHuman) {
if (_.get(req.app.locals, 'pc.open.apmrisk', false)) {
cache.setAsync(`${config.app}:limit2:${remoteIp}`, 1, limiterIpTime);
} else {
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, limiterIpTime);
}
req.session[sessionLimitKey] = true;
if (req.xhr) {
return res.status(510).json({
code: err.code,
data: {refer: checkRefer.replace(replaceKey, req.get('Referer') || '')}
});
}
return res.redirect(checkRefer.replace(replaceKey, req.protocol + '://' + req.get('host') + req.originalUrl));
}
if (_.get(req.app.locals, 'pc.open.apmrisk', false)) {
cache.setAsync(`${config.app}:limit2:${remoteIp}`, 1, limiterIpTime);
} else {
cache.setAsync(`${config.app}:limiter:${remoteIp}`, 1, limiterIpTime);
}
errorCode = 510;
}
req.session.apiRiskValidate = true;
if (!res.headersSent) {
if (req.xhr) {
return res.status(errorCode).json({
code: errorCode,
message: err.message || `服务器${errorCode === 510 ? '繁忙' : '错误'}!`
return res.status(510).json({
code: err.code,
data: {refer: checkRefer.replace(replaceKey, req.get('Referer') || '')}
});
}
const renderErrPage = (result) => {
result = result || {};
return res.redirect(checkRefer.replace(replaceKey, req.protocol + '://' + req.get('host') + req.originalUrl));
res.status(errorCode).render(`error/${errorCode}`, {
module: 'common',
page: 'error',
err: err,
title: `服务器${errorCode === 510 ? '繁忙' : '错误'} | Yoho!Buy有货 | 潮流购物逛不停`,
headerData: result.headerData
});
};
} else if (err.code === 9999991 || err.code === 9999992) {
return _err510(req, res, 510, err);
}
return req.ctx(headerModel).requestHeaderData(req.yoho.channel).then(renderErrPage).catch(() => {
renderErrPage();
});
if (!res.headersSent) {
return _err500(req, res, errorCode, err);
}
next(err);
return next(err);
};
};
... ...
... ... @@ -57,7 +57,7 @@
"urlencode": "^1.1.0",
"uuid": "^2.0.2",
"yoho-express-session": "^2.0.0",
"yoho-node-lib": "=0.6.33",
"yoho-node-lib": "=0.6.34",
"yoho-zookeeper": "^1.0.10",
"yo-cli": "=1.0.7"
},
... ...