Authored by 郝肖肖

逛详情页收藏APP跨域问题

@@ -43,6 +43,12 @@ const praiseArticle = (req, res, next) => { @@ -43,6 +43,12 @@ const praiseArticle = (req, res, next) => {
43 * 资讯文章收藏 (APP里显示收藏) 43 * 资讯文章收藏 (APP里显示收藏)
44 */ 44 */
45 const collectArticle = (req, res, next) => { 45 const collectArticle = (req, res, next) => {
  46 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  47 + req.headers.origin : req.protocol + '://' + req.headers.host;
  48 +
  49 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  50 + res.setHeader('Access-Control-Allow-Credentials', 'true');
  51 +
46 let result = { 52 let result = {
47 code: 400, 53 code: 400,
48 message: '您未登录,无法收藏或者取消收藏。请先登录!', 54 message: '您未登录,无法收藏或者取消收藏。请先登录!',
@@ -164,13 +164,16 @@ function initInfosEvt($container) { @@ -164,13 +164,16 @@ function initInfosEvt($container) {
164 164
165 $.ajax({ 165 $.ajax({
166 type: 'POST', 166 type: 'POST',
167 - url: '/guang/opt/collectArticle', 167 + url: location.protocol + '//m.yohobuy.com/guang/opt/collectArticle',
168 data: { 168 data: {
169 id: $info.data('id'), 169 id: $info.data('id'),
170 opt: opt, 170 opt: opt,
171 yh_channel: yhChannel, 171 yh_channel: yhChannel,
172 uid: uid 172 uid: uid
173 }, 173 },
  174 + xhrFields: {
  175 + withCredentials: true
  176 + },
174 success: function(data) { 177 success: function(data) {
175 if (data.code && data.code === 200) { 178 if (data.code && data.code === 200) {
176 179
@@ -157,6 +157,9 @@ function initInfosEvt($container) { @@ -157,6 +157,9 @@ function initInfosEvt($container) {
157 yh_channel: yhChannel, 157 yh_channel: yhChannel,
158 uid: getUrlParam('uid') 158 uid: getUrlParam('uid')
159 }, 159 },
  160 + xhrFields: {
  161 + withCredentials: true
  162 + },
160 success: function(data) { 163 success: function(data) {
161 if (data.code && data.code === 200) { 164 if (data.code && data.code === 200) {
162 // 切换收藏状态 165 // 切换收藏状态