Authored by 毕凯

Merge branch 'hotfix/servererr' into 'master'

Hotfix/servererr



See merge request !1160
... ... @@ -71,6 +71,14 @@ app.set('json replacer', function(key, value) {
return value;
});
app.use((req, res, next) => {
req.isApmReport = _.get(req.app.locals, 'wap.open.bughd', false); // 把错误上报的开关绑定到上下文,node-lib 库要使用
next();
});
// 添加请求上下文
app.use(global.yoho.httpCtx());
// 请求限制中间件
if (!app.locals.devEnv) {
app.use(require('./doraemon/middleware/limiter'));
... ... @@ -79,9 +87,6 @@ if (!app.locals.devEnv) {
// 指定libray目录
global.utils = path.resolve('./utils');
// 添加请求上下文
app.use(global.yoho.httpCtx());
// 访问域名层级
app.set('subdomain offset', 3);
... ... @@ -105,22 +110,20 @@ app.use(compression());
require('./doraemon/middleware/yoho-session')(app);
// 添加请求上下文
app.use(global.yoho.httpCtx());
app.use((req, res, next) => {
req.user = {}; // 全局的用户数据
req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等
req.app.locals.wap = app.locals.wap; // zookeper对象赋值
req.isApmReport = app.locals.wap.open && app.locals.wap.open.bughd; // 把错误上报的开关绑定到上下文,node-lib 库要使用
const udid = uuid.v4();
// 独立的 UDID
if (!req.cookies.udid) {
res.cookie('udid', uuid.v4(), {
res.cookie('udid', udid, {
domain: 'yohobuy.com',
expires: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000)
});
req.cookies.udid = udid;
}
next();
});
... ... @@ -176,6 +179,7 @@ try {
app.listen(config.port, function() {
logger.info('yohobuy start');
hbsEvent.event.on('hbs-complete', () => {
process.send && process.send('ready');
logger.info('hbs-all-complete');
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'dev') {
let {devHost, port} = require('./config/devtools');
... ...
... ... @@ -168,7 +168,7 @@ class BuyNowController {
use_yoho_coin: req.body.use_yoho_coin
});
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.use_yoho_coin = paymentProcess.transPrice(_.get(result, 'data.use_yoho_coin'));
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
return res.json(result.data);
})().catch(next);
... ...
... ... @@ -193,11 +193,13 @@ class BackNew {
let backCount = _.get(req.session, 'backupCaptch.count'); // 短信验证码 发送次数
if (!backCount) {
let timeout = _.parseInt(_.get(req, 'session.backupCaptch.timeout'));
/* 如果设置了冻结时间,验证 */
let untilTime = (parseInt(req.session.backupCaptch.timeout, 10) -
let untilTime = (timeout -
parseInt(Date.now(), 10)) / 1000 / 60;
if (parseInt(Date.now(), 10) < parseInt(req.session.backupCaptch.timeout, 10)) {
if (parseInt(Date.now(), 10) < timeout) {
return res.json({
code: 401,
message: '请' + (parseInt(untilTime, 10) + 1) + '分钟后尝试!'
... ...
... ... @@ -219,6 +219,8 @@ 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);
... ... @@ -226,7 +228,12 @@ const category = (req, res, next) => {
}
let params = Object.assign({}, req.query);
let seoTitle = decodeURIComponent(req.query.title || req.query.sort_name || '商品列表');
try {
seoTitle = decodeURIComponent(req.query.title || req.query.sort_name);
} catch (e) {
logger.error('decodeURIComponent seoTitle: ' + e);
}
/* 勿修改,唤起 APP 使用 */
let appParams = Object.assign({}, req.query, {
... ... @@ -287,7 +294,7 @@ const category = (req, res, next) => {
* 品类落地页 SEO 友好的新路由
*/
const listNew = (req, res, next) => {
req.query = listParamsProcess.getParams(req.url);
req.query = listParamsProcess.getParams(req.path);
if (req.query) {
_.forEach(req.query, (perParam, index) => {
... ... @@ -330,7 +337,7 @@ const listNew = (req, res, next) => {
let categoryIntroRedis = [];
let responseResult = {
list: productProcess.processProductList(result.data.product_list || [], {
list: productProcess.processProductList(_.get(result, 'data.product_list', []), {
isApp: params.isApp || (params.appVersion && params.appVersion !== 'false'),
gender: _coverChannel[params.coverChannel],
showSimilar: params.shop_id || params.material === 'true' ? false : true
... ...
... ... @@ -8,6 +8,7 @@ const helpers = global.yoho.helpers;
const sender = global.yoho.apmSender;
const hostname = require('os').hostname();
const routeEncode = require('./route-encode');
const _ = require('lodash');
const forceNoCache = (res) => {
if (res && !res.finished) {
... ... @@ -53,7 +54,7 @@ exports.serverError = () => {
return (err, req, res, next) => {
forceNoCache(res);
const uid = req.user ? req.user.uid : 0;
const udid = req.query.udid || req.cookies ? req.cookies._yasvd : 0;
const udid = _.get(req, 'cookies.udid', 'yoho');
if (req.isApmReport) {
// 上报服务端错误
... ...
... ... @@ -28,7 +28,7 @@
window._yohoAppName = 'yohobuywap-node';
window._router = '{{_router}}';
!function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var r={};t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var n=r(13),i=r(14);n.init(),i.init()},function(e,t){e.exports=function(e,t,r){if(void 0===t){var n=null;if(document.cookie)for(var i=document.cookie.split(";"),o=0;o<i.length;o++){var a=(i[o]||"").trim();if(a.substring(0,e.length+1)==e+"="){n=decodeURIComponent(a.substring(e.length+1));break}}return n}r=r||{},null===t&&(t="",r.expires=-1);var d="";if(r.expires&&("number"==typeof r.expires||r.expires.toUTCString)){var u;"number"==typeof r.expires?(u=new Date,u.setTime(u.getTime()+24*r.expires*60*60*1e3)):u=r.expires,d="; expires="+u.toUTCString()}var s=r.path?"; path="+r.path:"",p=r.domain?"; domain="+r.domain:"",c=r.secure?"; secure":"";document.cookie=[e,"=",encodeURIComponent(t),d,s,p,c].join("")}},,function(e,t,r){var n=r(1),i=window._yohoAppName||"unknown",o={config:{reportUrl:"//badjs.yoho.cn/apm/yas2.gif"},stringify:function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],i=[];for(var o in n)n.hasOwnProperty(o)&&i.push(o+"::"+n[o]);t.push(i.join("$$"))}return t.join("**")},report:function(e,t){if(e){(new Image).src=this.config.reportUrl+"?s="+i+"&l="+e+"&t="+(new Date).getTime(),t&&t()}},getUdid:function(){return(n("yohobuy_session")||"").slice(2).split(".")[0]||0},getUid:function(){return(n("_UID")||"").split("::")[1]||0},getReqId:function(){return n("docreqid")||0},getRoute:function(){return window._router||""}};e.exports=o},,,,,,,,,,function(e,t,r){var n=r(1),i=r(3),o="_errLog",a={writeError:function(e,t,r,a,d){var u=JSON.parse(n(o)||"[]");u.push({tp:"err",msg:e,sc:t,ln:r,cn:a,pt:location.href,u:i.getUid(),ud:i.getUdid(),rid:i.getReqId(),st:JSON.stringify(d&&d.stack),r:i.getRoute()}),n(o,JSON.stringify(u)),u.length>=5&&this.reportError()},clearError:function(){n(o,"[]")},reportError:function(){var e=this,t=JSON.parse(n(o)||"[]"),r=i.stringify(t);i.report(r,function(){e.clearError()})},init:function(){var e=this;window.onerror=function(t,r,n,i,o){e.writeError(t,r,n,i,o)},this.reportError()}};e.exports=a},function(e,t,r){function n(e){var t=e.offsetTop;return null!==e.offsetParent&&(t+=n(e.offsetParent)),t}var i=r(3),o=window.screen.height,a=[],d=!1,u=!1,s=0,p=setInterval(function(){var e,t;if(d){if(a.length)for(e=0;e<a.length;e++){if(t=a[e],!t.complete){u=!1;break}u=!0}else u=!0;u&&(s=(new Date).getTime()-_timeStart,clearInterval(p))}else{var r=document.body&&document.body.querySelectorAll("img")||[];for(e=0;e<r.length;e++){t=r[e];var i=n(t);if(i>o){d=!0;break}i<=o&&!t.hasPushed&&(t.hasPushed=1,a.push(t))}}},0),c={reportTime:function(e){var t=i.stringify(e);i.report(t)},addEvent:function(){var e=this,t=[],r=location.href,n=i.getUid(),o=i.getUdid(),a=i.getReqId(),c=window.performance&&window.performance.timing.navigationStart||0,f=i.getRoute();_timeStart=window._timeStart||0,document.addEventListener&&document.addEventListener("DOMContentLoaded",function(e){t.push({tp:"dcl",t:(new Date).getTime()-_timeStart,pt:r,u:n,ud:o,rid:a,r:f}),(document.body&&document.body.querySelectorAll("img")||[]).length||(d=!0)},!1),window.addEventListener&&window.addEventListener("load",function(i){t.push({tp:"ld",t:(new Date).getTime()-_timeStart,pt:r,u:n,ud:o,rid:a,r:f}),u=!0,d=!0,p&&clearInterval(p),s&&t.push({tp:"fs",t:s,pt:r,u:n,ud:o,rid:a,r:f}),t.push({tp:"pf",dcl:(window.performance&&window.performance.timing.domComplete||0)-c,ld:(window.performance&&window.performance.timing.loadEventStart||0)-c,pt:r,u:n,ud:o,rid:a,r:f}),e.reportTime(t)},!1)},init:function(){this.addEvent()}};e.exports=c}]);
!function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")});var n=r(13),o=r(14);n.init(),o.init()},function(e,t){e.exports=function(e,t,r){if(void 0===t){var n=null;if(document.cookie)for(var o=document.cookie.split(";"),i=0;i<o.length;i++){var d=(o[i]||"").trim();if(d.substring(0,e.length+1)==e+"="){n=decodeURIComponent(d.substring(e.length+1));break}}return n}r=r||{},null===t&&(t="",r.expires=-1);var a="";if(r.expires&&("number"==typeof r.expires||r.expires.toUTCString)){var u;"number"==typeof r.expires?(u=new Date,u.setTime(u.getTime()+24*r.expires*60*60*1e3)):u=r.expires,a="; expires="+u.toUTCString()}var p=r.path?"; path="+r.path:"",s=r.domain?"; domain="+r.domain:"",c=r.secure?"; secure":"";document.cookie=[e,"=",encodeURIComponent(t),a,p,s,c].join("")}},,function(e,t,r){var n=r(1),o=window._yohoAppName||"unknown",i={config:{reportUrl:"//badjs.yoho.cn/apm/yas2.gif"},stringify:function(e){for(var t=[],r=0;r<e.length;r++){var n=e[r],o=[];for(var i in n)n.hasOwnProperty(i)&&o.push(i+"::"+n[i]);t.push(o.join("$$"))}return t.join("**")},report:function(e,t){if(e){(new Image).src=this.config.reportUrl+"?s="+o+"&l="+e+"&t="+(new Date).getTime(),t&&t()}},getUdid:function(){return n("udid")||""||0},getUid:function(){return(n("_UID")||"").split("::")[1]||0},getReqId:function(){return n("docreqid")||0},getRoute:function(){return window._router||""}};e.exports=i},,,,,,,,,,function(e,t,r){var n=r(1),o=r(3),i="_errLog",d={writeError:function(e,t,r,d,a){var u=JSON.parse(n(i)||"[]");u.push({tp:"err",msg:e,sc:t,ln:r,cn:d,pt:encodeURIComponent(location.href),u:o.getUid(),ud:o.getUdid(),rid:o.getReqId(),st:JSON.stringify(a&&a.stack),r:o.getRoute()}),n(i,JSON.stringify(u)),u.length>=5&&this.reportError()},clearError:function(){n(i,"[]")},reportError:function(){var e=this,t=JSON.parse(n(i)||"[]"),r=o.stringify(t);o.report(r,function(){e.clearError()})},init:function(){var e=this;window.onerror=function(t,r,n,o,i){e.writeError(t,r,n,o,i)},this.reportError()}};e.exports=d},function(e,t,r){function n(e){var t=e.offsetTop;return null!==e.offsetParent&&(t+=n(e.offsetParent)),t}var o=r(3),i=window.screen.height,d=[],a=!1,u=!1,p=0,s=setInterval(function(){var e,t;if(a){if(d.length)for(e=0;e<d.length;e++){if(t=d[e],!t.complete){u=!1;break}u=!0}else u=!0;u&&(p=(new Date).getTime()-_timeStart,clearInterval(s))}else{var r=document.body&&document.body.querySelectorAll("img")||[];for(e=0;e<r.length;e++){t=r[e];var o=n(t);if(o>i){a=!0;break}o<=i&&!t.hasPushed&&(t.hasPushed=1,d.push(t))}}},0),c={reportTime:function(e){var t=o.stringify(e);o.report(t)},addEvent:function(){var e=this,t=[],r=encodeURIComponent(location.href),n=o.getUid(),i=o.getUdid(),d=o.getReqId(),c=window.performance&&window.performance.timing.navigationStart||0,f=o.getRoute();_timeStart=window._timeStart||0,document.addEventListener&&document.addEventListener("DOMContentLoaded",function(e){t.push({tp:"dcl",t:(new Date).getTime()-_timeStart,pt:r,u:n,ud:i,rid:d,r:f}),(document.body&&document.body.querySelectorAll("img")||[]).length||(a=!0)},!1),window.addEventListener&&window.addEventListener("load",function(o){t.push({tp:"ld",t:(new Date).getTime()-_timeStart,pt:r,u:n,ud:i,rid:d,r:f}),u=!0,a=!0,s&&clearInterval(s),p&&t.push({tp:"fs",t:p,pt:r,u:n,ud:i,rid:d,r:f}),t.push({tp:"pf",dcl:(window.performance&&window.performance.timing.domComplete||0)-c,ld:(window.performance&&window.performance.timing.loadEventStart||0)-c,pt:r,u:n,ud:i,rid:d,r:f}),e.reportTime(t)},!1)},init:function(){this.addEvent()}};e.exports=c}]);
{{/ifand}}
</script>
... ...
... ... @@ -73,7 +73,7 @@
"xml2js": "^0.4.19",
"yoho-express-session": "^2.0.0",
"yoho-md5": "^2.0.0",
"yoho-node-lib": "=0.5.29",
"yoho-node-lib": "=0.5.36",
"yoho-zookeeper": "^1.0.8"
},
"devDependencies": {
... ...
... ... @@ -5,6 +5,7 @@
"script": "app.js",
"instances": "4",
"exec_mode": "cluster",
"wait_ready": true,
"merge_logs": true,
"log_date_format": "YYYY-MM-DD HH:mm:ss Z",
"error_file": "/Data/logs/node/yohobuywap-node-err.log",
... ...
... ... @@ -403,7 +403,11 @@ const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isW
let cover = _.get(item, 'cover', '');
_.forEach(_.get(item, 'list', []), item2 => {
allgoods += item2.id + ',';
let goodId = _.get(item2, 'id');
if (goodId) {
allgoods += goodId + ',';
}
});
collocation.push({
... ...