Authored by 郝肖肖

品牌领券请求列表,跨域修复

@@ -520,6 +520,12 @@ const userCoupon = (req, res, next) => { @@ -520,6 +520,12 @@ const userCoupon = (req, res, next) => {
520 * @param next 520 * @param next
521 */ 521 */
522 const getShopCouponsList = (req, res, next) => { 522 const getShopCouponsList = (req, res, next) => {
  523 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  524 + req.headers.origin : req.protocol + '://' + req.headers.host;
  525 +
  526 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  527 + res.setHeader('Access-Control-Allow-Credentials', 'true');
  528 +
523 let uid = req.query.uid || req.user.uid; 529 let uid = req.query.uid || req.user.uid;
524 let shopId = req.query.shopId; 530 let shopId = req.query.shopId;
525 let param = {}; 531 let param = {};
@@ -542,6 +548,12 @@ const getShopCouponsList = (req, res, next) => { @@ -542,6 +548,12 @@ const getShopCouponsList = (req, res, next) => {
542 * @param next 548 * @param next
543 */ 549 */
544 const getBrandCouponsList = (req, res, next) => { 550 const getBrandCouponsList = (req, res, next) => {
  551 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  552 + req.headers.origin : req.protocol + '://' + req.headers.host;
  553 +
  554 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  555 + res.setHeader('Access-Control-Allow-Credentials', 'true');
  556 +
545 let uid = req.query.uid || req.user.uid; 557 let uid = req.query.uid || req.user.uid;
546 let brandId = req.query.brandId; 558 let brandId = req.query.brandId;
547 let param = {}; 559 let param = {};
@@ -10,8 +10,8 @@ shopCoupon = { @@ -10,8 +10,8 @@ shopCoupon = {
10 common: { 10 common: {
11 appVersion: window.queryString.app_version || window.queryString.appVersion, 11 appVersion: window.queryString.app_version || window.queryString.appVersion,
12 uid: window.queryString.uid, 12 uid: window.queryString.uid,
13 - shopId: $('.shop-id').val(),  
14 - brandId: $('.brand-header').data('id'), 13 + shopId: $('.shop-id').val() || '',
  14 + brandId: $('.brand-header').data('id') || '',
15 couponTemplate: require('product/shop/coupon.hbs') 15 couponTemplate: require('product/shop/coupon.hbs')
16 }, 16 },
17 init: function() { 17 init: function() {
@@ -24,10 +24,10 @@ shopCoupon = { @@ -24,10 +24,10 @@ shopCoupon = {
24 24
25 if (that.common.shopId === '') { 25 if (that.common.shopId === '') {
26 //品牌领券 26 //品牌领券
27 - _url = '/product/index/getBrandCouponsList'; 27 + _url += '/product/index/getBrandCouponsList';
28 } else { 28 } else {
29 //店铺领券 29 //店铺领券
30 - _url = '/product/index/getShopCouponsList'; 30 + _url += '/product/index/getShopCouponsList';
31 } 31 }
32 32
33 $.ajax({ 33 $.ajax({