Authored by 毕凯

Merge branch 'hotfix/srverr' into 'master'

Hotfix/srverr



See merge request !1177
... ... @@ -54,23 +54,6 @@ app.enable('trust proxy');
app.disable('x-powered-by');
const safeStringify = require('fast-safe-stringify');
// 循环对象检测
app.set('json replacer', function(key, value) {
if (!key) {
let safeStr = safeStringify(value) || '{}';
if (/\[Circular\]/.test(safeStr)) {
logger.error('stringify error:', value);
}
return JSON.parse(safeStr);
}
return value;
});
app.use((req, res, next) => {
req.isApmReport = _.get(req.app.locals, 'wap.open.bughd', false); // 把错误上报的开关绑定到上下文,node-lib 库要使用
next();
... ...
... ... @@ -33,7 +33,7 @@ module.exports = class extends global.yoho.BaseModel {
});
_.map(list, function(item, key) {
item.focus = key === channel;
_.set(item, 'focus', key === channel);
_.map(item, function(firstItem) {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
... ...
... ... @@ -168,7 +168,7 @@ class IndexModel extends global.yoho.BaseModel {
let inf = [];
cateList.forEach(val => {
_.forEach(cateList, val => {
build.push({
typeId: val.id,
type: val.name,
... ... @@ -226,7 +226,7 @@ class IndexModel extends global.yoho.BaseModel {
inf.push(guangProcess.formatArticle(val, true, false, true));
});
resu.guang.infos[curIndex].info = inf;
_.set(resu, `guang.infos[${curIndex}].info`, inf);
return resu;
... ...
... ... @@ -457,7 +457,7 @@ class familyModel extends global.yoho.BaseModel {
head_ico: perInfo.headIco,
nickname: perInfo.nickName,
gender: parseInt(perInfo.gender, 10),
birthday: perInfo.birthday ? moment(perInfo.birthday).format('MM-DD') : '',
birthday: perInfo.birthday ? moment(new Date(perInfo.birthday)).format('MM-DD') : '',
province: perInfo.province,
city: perInfo.city
});
... ...
... ... @@ -219,8 +219,6 @@ const shopFav = (req, res) => {
// 品类落地页
const category = (req, res, next) => {
let seoTitle = '商品列表';
if (req.query) {
_.forEach(req.query, (perParam, index) => {
req.query[index] = stringProcess.paramsFilter(perParam);
... ... @@ -228,11 +226,10 @@ const category = (req, res, next) => {
}
let params = Object.assign({}, req.query);
let seoTitle;
try {
seoTitle = decodeURIComponent(req.query.title || req.query.sort_name);
} catch (e) {
logger.error(`decodeURIComponent seoTitle:${e}url:${req.url}`);
if (req.query.title || req.query.sort_name) {
seoTitle = stringProcess.decodeURIComponent(req.query.title || req.query.sort_name);
}
/* 勿修改,唤起 APP 使用 */
... ... @@ -275,7 +272,7 @@ const category = (req, res, next) => {
// currentHref: 'https://www.yohobuy.com/list?' // TODO
// },
pageHeader: headerModel.setNav({
navTitle: seoTitle
navTitle: seoTitle || '商品列表'
}),
goodList: params,
firstPageGoods: firstPageGoods || [],
... ... @@ -358,16 +355,8 @@ const listNew = (req, res, next) => {
let seoTitle = _.get(seoParams, 'sort');
let paramsTitle = params.title || params.sort_name; // 可能会配置的标题,优先级最高
if (!seoTitle) {
seoTitle = '商品列表';
}
if (paramsTitle) {
try {
seoTitle = decodeURIComponent(paramsTitle);
} catch (e) {
logger.error(`decodeURIComponent seoTitle:${e}url:${req.url}`);
}
seoTitle = stringProcess.decodeURIComponent(paramsTitle);
}
try {
... ... @@ -390,7 +379,7 @@ const listNew = (req, res, next) => {
currentHref: `https://www.yohobuy.com${req.url}`
},
pageHeader: headerModel.setNav({
navTitle: seoTitle
navTitle: seoTitle || '商品列表'
}),
goodList: params,
firstPageGoods: responseResult || [],
... ...
... ... @@ -76,9 +76,10 @@ module.exports = {
maxFiles: 7
},
console: {
level: 'info',
level: 'debug',
colorize: 'all',
prettyPrint: true
prettyPrint: true,
debugStdout: true
}
},
thirdLogin: {
... ... @@ -111,7 +112,7 @@ module.exports = {
maxQps: 1200,
maxQps10m: 2500,
geetestJs: '//static.geetest.com/static/tools/gt.js',
jsSdk: '//cdn.yoho.cn/js-sdk/1.2.9/jssdk.js',
jsSdk: '//cdn.yoho.cn/js-sdk/1.2.10/jssdk.js',
redis: {
connect: {
host: '127.0.0.1',
... ... @@ -218,6 +219,29 @@ if (isProduction) {
host: 'badjs.yoho.cn',
port: 80,
db: 'web-apm'
},
loggers: {
infoFile: {
close: true,
name: 'info',
level: 'error',
filename: 'logs/info.log',
maxFiles: 7
},
errorFile: {
close: true,
name: 'error',
level: 'error',
filename: 'logs/error.log',
handleExceptions: true,
maxFiles: 7
},
console: {
level: 'info',
colorize: 'all',
prettyPrint: true,
debugStdout: true
}
}
});
} else if (isTest) {
... ...
... ... @@ -64,7 +64,7 @@ exports.serverError = () => {
app: global.yoho.config.appName, // 应用名称
hostname,
type: 'server',
route: `[${req.method}]${req.route.path}`, // 请求路由
route: `[${req.method}]${_.get(req, 'route.path', '')}`, // 请求路由
reqID: req.reqID,
uid,
udid,
... ...
... ... @@ -51,7 +51,6 @@
"cookie-parser": "^1.4.3",
"cssnano": "^3.10.0",
"express": "^4.15.4",
"fast-safe-stringify": "^1.2.0",
"feed": "^1.1.0",
"geetest": "^4.1.2",
"lodash": "^4.17.4",
... ... @@ -69,6 +68,7 @@
"request-promise": "^4.2.1",
"semver": "^5.4.1",
"sitemap": "^1.13.0",
"urlencode": "^1.1.0",
"uuid": "^3.1.0",
"xml2js": "^0.4.19",
"yoho-express-session": "^2.0.0",
... ...
... ... @@ -3,8 +3,8 @@
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/7/29
*/
const logger = global.yoho.logger;
const _ = require('lodash');
const stringProcess = require('./string-process');
/**
* 根据频道判断出性别
... ... @@ -194,7 +194,6 @@ const getListSeoData = (params) => {
if (params) {
_.assign(seoParams, params);
console.log(seoParams);
let baseInfo = `${seoParams.brand}${seoParams.sort}`;
... ... @@ -220,13 +219,8 @@ const getSearchParamsWithoutMethod = (params) => {
};
if (params.query) { // 模糊查询参数
let queryString = '';
let queryString = stringProcess.decodeURIComponent(params.query).replace(/\+/g, ',');
try {
queryString = decodeURIComponent(params.query).replace(/\+/g, ',');
} catch (e) {
logger.error('decodeURIComponent params query: ' + e);
}
finalParams.query = queryString;
}
if (params.yh_channel || params.channel) { // 频道
... ...
... ... @@ -4,6 +4,8 @@
'use strict';
const _ = require('lodash');
const urlencode = require('urlencode');
const logger = global.yoho.logger;
/**
* [判断数字]
... ... @@ -26,7 +28,28 @@ const paramsFilter = (param) => {
}
};
/**
* 解决 decodeURIComponent 字符串编码不同的工具
*/
const decodeURIComponent = (param) => {
let result = '';
try {
result = urlencode.decode(param);
} catch (e) {
try {
result = urlencode.decode(param, 'gbk');
} catch (e2) {
logger.error(`decodeURIComponent param:${e2}url:${param}`);
}
}
return result;
};
module.exports = {
isNumeric,
paramsFilter
paramsFilter,
decodeURIComponent
};
... ...