Authored by 毕凯

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

@@ -4,6 +4,7 @@ const _ = require('lodash'); @@ -4,6 +4,7 @@ const _ = require('lodash');
4 const cookie = global.yoho.cookie; 4 const cookie = global.yoho.cookie;
5 const authcode = require('../../utils/authcode'); 5 const authcode = require('../../utils/authcode');
6 const config = global.yoho.config; 6 const config = global.yoho.config;
  7 +const logger = global.yoho.logger;
7 8
8 module.exports = () => { 9 module.exports = () => {
9 return (req, res, next) => { 10 return (req, res, next) => {
@@ -69,6 +70,10 @@ module.exports = () => { @@ -69,6 +70,10 @@ module.exports = () => {
69 let appVersion = req.query.app_version || req.cookies.app_version || config.appVersion; 70 let appVersion = req.query.app_version || req.cookies.app_version || config.appVersion;
70 let appSessionType = req.query.client_type || req.cookies.app_client_type; 71 let appSessionType = req.query.client_type || req.cookies.app_client_type;
71 72
  73 + if (req.query.app_version && req.query.client_type) {
  74 + logger.warn(`app session from querystring, url:${req.url}`);
  75 + }
  76 +
72 req.query.uid = { 77 req.query.uid = {
73 toString: () => { 78 toString: () => {
74 return _.parseInt(appUid); 79 return _.parseInt(appUid);
@@ -76,9 +81,11 @@ module.exports = () => { @@ -76,9 +81,11 @@ module.exports = () => {
76 appVersion: appVersion, 81 appVersion: appVersion,
77 appSessionType: appSessionType 82 appSessionType: appSessionType
78 }; 83 };
79 - res.cookie('app_uid', appUid.toString());  
80 - res.cookie('app_version', appVersion);  
81 - res.cookie('app_client_type', appSessionType); 84 +
  85 + // 此处 cookie 为了 pagecache 放到前端去写
  86 + // res.cookie('app_uid', appUid.toString());
  87 + // res.cookie('app_version', appVersion);
  88 + // res.cookie('app_client_type', appSessionType);
82 } 89 }
83 } 90 }
84 91
@@ -5,10 +5,21 @@ @@ -5,10 +5,21 @@
5 */ 5 */
6 const $ = require('yoho-jquery'); 6 const $ = require('yoho-jquery');
7 const cookie = require('yoho-cookie'); 7 const cookie = require('yoho-cookie');
  8 +const qs = require('yoho-qs');
8 const tip = require('plugin/tip'); 9 const tip = require('plugin/tip');
9 const yoho = require('./yoho-app'); 10 const yoho = require('./yoho-app');
10 11
11 -// 初始化 12 +
  13 +// App 的信息需要存下来
  14 +if (yoho.isApp && qs.uid && qs.app_version && qs.client_type) {
  15 + const options = {
  16 + path: '/'
  17 + };
  18 +
  19 + cookie.set('app_uid', qs.uid, options);
  20 + cookie.set('app_version', qs.app_version, options);
  21 + cookie.set('app_client_type', qs.client_type, options);
  22 +}
12 23
13 // 注册ajaxError处理服务端401状态 24 // 注册ajaxError处理服务端401状态
14 $(document).ajaxError((event, xhr) => { 25 $(document).ajaxError((event, xhr) => {