Authored by 毕凯

App 相关session放到浏览器端去写

... ... @@ -4,6 +4,7 @@ const _ = require('lodash');
const cookie = global.yoho.cookie;
const authcode = require('../../utils/authcode');
const config = global.yoho.config;
const logger = global.yoho.logger;
module.exports = () => {
return (req, res, next) => {
... ... @@ -69,6 +70,10 @@ module.exports = () => {
let appVersion = req.query.app_version || req.cookies.app_version || config.appVersion;
let appSessionType = req.query.client_type || req.cookies.app_client_type;
if (req.query.app_version && req.query.client_type) {
logger.warn(`app session from querystring, url:${req.url}`);
}
req.query.uid = {
toString: () => {
return _.parseInt(appUid);
... ... @@ -76,9 +81,11 @@ module.exports = () => {
appVersion: appVersion,
appSessionType: appSessionType
};
res.cookie('app_uid', appUid.toString());
res.cookie('app_version', appVersion);
res.cookie('app_client_type', appSessionType);
// 此处 cookie 为了 pagecache 放到前端去写
// res.cookie('app_uid', appUid.toString());
// res.cookie('app_version', appVersion);
// res.cookie('app_client_type', appSessionType);
}
}
... ...
... ... @@ -5,10 +5,21 @@
*/
const $ = require('yoho-jquery');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
const tip = require('plugin/tip');
const yoho = require('./yoho-app');
// 初始化
// App 的信息需要存下来
if (yoho.isApp && qs.uid && qs.app_version && qs.client_type) {
const options = {
path: '/'
};
cookie.set('app_uid', qs.uid, options);
cookie.set('app_version', qs.app_version, options);
cookie.set('app_client_type', qs.client_type, options);
}
// 注册ajaxError处理服务端401状态
$(document).ajaxError((event, xhr) => {
... ...