Authored by 毕凯

Merge branch 'hotfix/srverr' into 'master'

Hotfix/srverr



See merge request !1177
@@ -54,23 +54,6 @@ app.enable('trust proxy'); @@ -54,23 +54,6 @@ app.enable('trust proxy');
54 54
55 app.disable('x-powered-by'); 55 app.disable('x-powered-by');
56 56
57 -const safeStringify = require('fast-safe-stringify');  
58 -  
59 -// 循环对象检测  
60 -app.set('json replacer', function(key, value) {  
61 - if (!key) {  
62 - let safeStr = safeStringify(value) || '{}';  
63 -  
64 - if (/\[Circular\]/.test(safeStr)) {  
65 - logger.error('stringify error:', value);  
66 - }  
67 -  
68 - return JSON.parse(safeStr);  
69 - }  
70 -  
71 - return value;  
72 -});  
73 -  
74 app.use((req, res, next) => { 57 app.use((req, res, next) => {
75 req.isApmReport = _.get(req.app.locals, 'wap.open.bughd', false); // 把错误上报的开关绑定到上下文,node-lib 库要使用 58 req.isApmReport = _.get(req.app.locals, 'wap.open.bughd', false); // 把错误上报的开关绑定到上下文,node-lib 库要使用
76 next(); 59 next();
@@ -33,7 +33,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -33,7 +33,7 @@ module.exports = class extends global.yoho.BaseModel {
33 }); 33 });
34 34
35 _.map(list, function(item, key) { 35 _.map(list, function(item, key) {
36 - item.focus = key === channel; 36 + _.set(item, 'focus', key === channel);
37 37
38 _.map(item, function(firstItem) { 38 _.map(item, function(firstItem) {
39 // 如果有二级菜单,二级菜单跳转,否则一级菜单跳转 39 // 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
@@ -168,7 +168,7 @@ class IndexModel extends global.yoho.BaseModel { @@ -168,7 +168,7 @@ class IndexModel extends global.yoho.BaseModel {
168 168
169 let inf = []; 169 let inf = [];
170 170
171 - cateList.forEach(val => { 171 + _.forEach(cateList, val => {
172 build.push({ 172 build.push({
173 typeId: val.id, 173 typeId: val.id,
174 type: val.name, 174 type: val.name,
@@ -226,7 +226,7 @@ class IndexModel extends global.yoho.BaseModel { @@ -226,7 +226,7 @@ class IndexModel extends global.yoho.BaseModel {
226 inf.push(guangProcess.formatArticle(val, true, false, true)); 226 inf.push(guangProcess.formatArticle(val, true, false, true));
227 }); 227 });
228 228
229 - resu.guang.infos[curIndex].info = inf; 229 + _.set(resu, `guang.infos[${curIndex}].info`, inf);
230 230
231 return resu; 231 return resu;
232 232
@@ -457,7 +457,7 @@ class familyModel extends global.yoho.BaseModel { @@ -457,7 +457,7 @@ class familyModel extends global.yoho.BaseModel {
457 head_ico: perInfo.headIco, 457 head_ico: perInfo.headIco,
458 nickname: perInfo.nickName, 458 nickname: perInfo.nickName,
459 gender: parseInt(perInfo.gender, 10), 459 gender: parseInt(perInfo.gender, 10),
460 - birthday: perInfo.birthday ? moment(perInfo.birthday).format('MM-DD') : '', 460 + birthday: perInfo.birthday ? moment(new Date(perInfo.birthday)).format('MM-DD') : '',
461 province: perInfo.province, 461 province: perInfo.province,
462 city: perInfo.city 462 city: perInfo.city
463 }); 463 });
@@ -219,8 +219,6 @@ const shopFav = (req, res) => { @@ -219,8 +219,6 @@ const shopFav = (req, res) => {
219 219
220 // 品类落地页 220 // 品类落地页
221 const category = (req, res, next) => { 221 const category = (req, res, next) => {
222 - let seoTitle = '商品列表';  
223 -  
224 if (req.query) { 222 if (req.query) {
225 _.forEach(req.query, (perParam, index) => { 223 _.forEach(req.query, (perParam, index) => {
226 req.query[index] = stringProcess.paramsFilter(perParam); 224 req.query[index] = stringProcess.paramsFilter(perParam);
@@ -228,11 +226,10 @@ const category = (req, res, next) => { @@ -228,11 +226,10 @@ const category = (req, res, next) => {
228 } 226 }
229 227
230 let params = Object.assign({}, req.query); 228 let params = Object.assign({}, req.query);
  229 + let seoTitle;
231 230
232 - try {  
233 - seoTitle = decodeURIComponent(req.query.title || req.query.sort_name);  
234 - } catch (e) {  
235 - logger.error(`decodeURIComponent seoTitle:${e}url:${req.url}`); 231 + if (req.query.title || req.query.sort_name) {
  232 + seoTitle = stringProcess.decodeURIComponent(req.query.title || req.query.sort_name);
236 } 233 }
237 234
238 /* 勿修改,唤起 APP 使用 */ 235 /* 勿修改,唤起 APP 使用 */
@@ -275,7 +272,7 @@ const category = (req, res, next) => { @@ -275,7 +272,7 @@ const category = (req, res, next) => {
275 // currentHref: 'https://www.yohobuy.com/list?' // TODO 272 // currentHref: 'https://www.yohobuy.com/list?' // TODO
276 // }, 273 // },
277 pageHeader: headerModel.setNav({ 274 pageHeader: headerModel.setNav({
278 - navTitle: seoTitle 275 + navTitle: seoTitle || '商品列表'
279 }), 276 }),
280 goodList: params, 277 goodList: params,
281 firstPageGoods: firstPageGoods || [], 278 firstPageGoods: firstPageGoods || [],
@@ -358,16 +355,8 @@ const listNew = (req, res, next) => { @@ -358,16 +355,8 @@ const listNew = (req, res, next) => {
358 let seoTitle = _.get(seoParams, 'sort'); 355 let seoTitle = _.get(seoParams, 'sort');
359 let paramsTitle = params.title || params.sort_name; // 可能会配置的标题,优先级最高 356 let paramsTitle = params.title || params.sort_name; // 可能会配置的标题,优先级最高
360 357
361 - if (!seoTitle) {  
362 - seoTitle = '商品列表';  
363 - }  
364 -  
365 if (paramsTitle) { 358 if (paramsTitle) {
366 - try {  
367 - seoTitle = decodeURIComponent(paramsTitle);  
368 - } catch (e) {  
369 - logger.error(`decodeURIComponent seoTitle:${e}url:${req.url}`);  
370 - } 359 + seoTitle = stringProcess.decodeURIComponent(paramsTitle);
371 } 360 }
372 361
373 try { 362 try {
@@ -390,7 +379,7 @@ const listNew = (req, res, next) => { @@ -390,7 +379,7 @@ const listNew = (req, res, next) => {
390 currentHref: `https://www.yohobuy.com${req.url}` 379 currentHref: `https://www.yohobuy.com${req.url}`
391 }, 380 },
392 pageHeader: headerModel.setNav({ 381 pageHeader: headerModel.setNav({
393 - navTitle: seoTitle 382 + navTitle: seoTitle || '商品列表'
394 }), 383 }),
395 goodList: params, 384 goodList: params,
396 firstPageGoods: responseResult || [], 385 firstPageGoods: responseResult || [],
@@ -76,9 +76,10 @@ module.exports = { @@ -76,9 +76,10 @@ module.exports = {
76 maxFiles: 7 76 maxFiles: 7
77 }, 77 },
78 console: { 78 console: {
79 - level: 'info', 79 + level: 'debug',
80 colorize: 'all', 80 colorize: 'all',
81 - prettyPrint: true 81 + prettyPrint: true,
  82 + debugStdout: true
82 } 83 }
83 }, 84 },
84 thirdLogin: { 85 thirdLogin: {
@@ -111,7 +112,7 @@ module.exports = { @@ -111,7 +112,7 @@ module.exports = {
111 maxQps: 1200, 112 maxQps: 1200,
112 maxQps10m: 2500, 113 maxQps10m: 2500,
113 geetestJs: '//static.geetest.com/static/tools/gt.js', 114 geetestJs: '//static.geetest.com/static/tools/gt.js',
114 - jsSdk: '//cdn.yoho.cn/js-sdk/1.2.9/jssdk.js', 115 + jsSdk: '//cdn.yoho.cn/js-sdk/1.2.10/jssdk.js',
115 redis: { 116 redis: {
116 connect: { 117 connect: {
117 host: '127.0.0.1', 118 host: '127.0.0.1',
@@ -218,6 +219,29 @@ if (isProduction) { @@ -218,6 +219,29 @@ if (isProduction) {
218 host: 'badjs.yoho.cn', 219 host: 'badjs.yoho.cn',
219 port: 80, 220 port: 80,
220 db: 'web-apm' 221 db: 'web-apm'
  222 + },
  223 + loggers: {
  224 + infoFile: {
  225 + close: true,
  226 + name: 'info',
  227 + level: 'error',
  228 + filename: 'logs/info.log',
  229 + maxFiles: 7
  230 + },
  231 + errorFile: {
  232 + close: true,
  233 + name: 'error',
  234 + level: 'error',
  235 + filename: 'logs/error.log',
  236 + handleExceptions: true,
  237 + maxFiles: 7
  238 + },
  239 + console: {
  240 + level: 'info',
  241 + colorize: 'all',
  242 + prettyPrint: true,
  243 + debugStdout: true
  244 + }
221 } 245 }
222 }); 246 });
223 } else if (isTest) { 247 } else if (isTest) {
@@ -64,7 +64,7 @@ exports.serverError = () => { @@ -64,7 +64,7 @@ exports.serverError = () => {
64 app: global.yoho.config.appName, // 应用名称 64 app: global.yoho.config.appName, // 应用名称
65 hostname, 65 hostname,
66 type: 'server', 66 type: 'server',
67 - route: `[${req.method}]${req.route.path}`, // 请求路由 67 + route: `[${req.method}]${_.get(req, 'route.path', '')}`, // 请求路由
68 reqID: req.reqID, 68 reqID: req.reqID,
69 uid, 69 uid,
70 udid, 70 udid,
@@ -51,7 +51,6 @@ @@ -51,7 +51,6 @@
51 "cookie-parser": "^1.4.3", 51 "cookie-parser": "^1.4.3",
52 "cssnano": "^3.10.0", 52 "cssnano": "^3.10.0",
53 "express": "^4.15.4", 53 "express": "^4.15.4",
54 - "fast-safe-stringify": "^1.2.0",  
55 "feed": "^1.1.0", 54 "feed": "^1.1.0",
56 "geetest": "^4.1.2", 55 "geetest": "^4.1.2",
57 "lodash": "^4.17.4", 56 "lodash": "^4.17.4",
@@ -69,6 +68,7 @@ @@ -69,6 +68,7 @@
69 "request-promise": "^4.2.1", 68 "request-promise": "^4.2.1",
70 "semver": "^5.4.1", 69 "semver": "^5.4.1",
71 "sitemap": "^1.13.0", 70 "sitemap": "^1.13.0",
  71 + "urlencode": "^1.1.0",
72 "uuid": "^3.1.0", 72 "uuid": "^3.1.0",
73 "xml2js": "^0.4.19", 73 "xml2js": "^0.4.19",
74 "yoho-express-session": "^2.0.0", 74 "yoho-express-session": "^2.0.0",
@@ -3,8 +3,8 @@ @@ -3,8 +3,8 @@
3 * @author: wsl<shuiling.wang@yoho.cn> 3 * @author: wsl<shuiling.wang@yoho.cn>
4 * @date: 2016/7/29 4 * @date: 2016/7/29
5 */ 5 */
6 -const logger = global.yoho.logger;  
7 const _ = require('lodash'); 6 const _ = require('lodash');
  7 +const stringProcess = require('./string-process');
8 8
9 /** 9 /**
10 * 根据频道判断出性别 10 * 根据频道判断出性别
@@ -194,7 +194,6 @@ const getListSeoData = (params) => { @@ -194,7 +194,6 @@ const getListSeoData = (params) => {
194 194
195 if (params) { 195 if (params) {
196 _.assign(seoParams, params); 196 _.assign(seoParams, params);
197 - console.log(seoParams);  
198 197
199 let baseInfo = `${seoParams.brand}${seoParams.sort}`; 198 let baseInfo = `${seoParams.brand}${seoParams.sort}`;
200 199
@@ -220,13 +219,8 @@ const getSearchParamsWithoutMethod = (params) => { @@ -220,13 +219,8 @@ const getSearchParamsWithoutMethod = (params) => {
220 }; 219 };
221 220
222 if (params.query) { // 模糊查询参数 221 if (params.query) { // 模糊查询参数
223 - let queryString = ''; 222 + let queryString = stringProcess.decodeURIComponent(params.query).replace(/\+/g, ',');
224 223
225 - try {  
226 - queryString = decodeURIComponent(params.query).replace(/\+/g, ',');  
227 - } catch (e) {  
228 - logger.error('decodeURIComponent params query: ' + e);  
229 - }  
230 finalParams.query = queryString; 224 finalParams.query = queryString;
231 } 225 }
232 if (params.yh_channel || params.channel) { // 频道 226 if (params.yh_channel || params.channel) { // 频道
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 4
5 'use strict'; 5 'use strict';
6 const _ = require('lodash'); 6 const _ = require('lodash');
  7 +const urlencode = require('urlencode');
  8 +const logger = global.yoho.logger;
7 9
8 /** 10 /**
9 * [判断数字] 11 * [判断数字]
@@ -26,7 +28,28 @@ const paramsFilter = (param) => { @@ -26,7 +28,28 @@ const paramsFilter = (param) => {
26 } 28 }
27 }; 29 };
28 30
  31 +/**
  32 + * 解决 decodeURIComponent 字符串编码不同的工具
  33 + */
  34 +
  35 +const decodeURIComponent = (param) => {
  36 + let result = '';
  37 +
  38 + try {
  39 + result = urlencode.decode(param);
  40 + } catch (e) {
  41 + try {
  42 + result = urlencode.decode(param, 'gbk');
  43 + } catch (e2) {
  44 + logger.error(`decodeURIComponent param:${e2}url:${param}`);
  45 + }
  46 + }
  47 +
  48 + return result;
  49 +};
  50 +
29 module.exports = { 51 module.exports = {
30 isNumeric, 52 isNumeric,
31 - paramsFilter 53 + paramsFilter,
  54 + decodeURIComponent
32 }; 55 };