diff --git a/server/vue-middleware.js b/server/vue-middleware.js index 53971f9bc8..c1c0048987 100644 --- a/server/vue-middleware.js +++ b/server/vue-middleware.js @@ -68,25 +68,33 @@ module.exports = function createMiddleware({ const targetCookies = ['kvbskt', 'kvls', 'kvu', 'kv']; let cookieMessage = 'Cookie info:'; - targetCookies.forEach(cookieKey => { - if (typeof cookies[cookieKey] !== 'string') { - cookieMessage += ` missing ${cookieKey} cookie,`; - } else { - cookieMessage += ` ${cookieKey} cookie: ${cookies[cookieKey]},`; - } - }); - console.info(cookieMessage); + if (typeof cookies === 'object') { + targetCookies.forEach(cookieKey => { + if (typeof cookies[cookieKey] !== 'string') { + cookieMessage += ` missing ${cookieKey} cookie,`; + } else { + cookieMessage += ` ${cookieKey} cookie: ${cookies[cookieKey]},`; + } + }); + console.info(cookieMessage); + } else { + console.info('missing cookie object'); + } const targetReqUser = ['id', 'user_id', 'accessToken']; let reqUserMessage = 'req.user info:'; - targetReqUser.forEach(reqUserKey => { - if (typeof req.user[reqUserKey] !== 'string') { - reqUserMessage += ` missing req.user ${reqUserKey},`; - } else { - reqUserMessage += ` req.user ${reqUserKey}: ${req.user[reqUserKey].substring(0, 25)},`; - } - }); - console.info(reqUserMessage); + if (req && req.user && typeof req.user === 'object') { + targetReqUser.forEach(reqUserKey => { + if (typeof req.user[reqUserKey] !== 'string') { + reqUserMessage += ` missing req.user ${reqUserKey},`; + } else { + reqUserMessage += ` req.user ${reqUserKey}: ${req.user[reqUserKey].substring(0, 25)},`; + } + }); + console.info(reqUserMessage); + } else { + console.info('missing req.user object'); + } // set html response headers res.setHeader('Content-Type', 'text/html');