Authored by 郭成尧

cors

@@ -345,6 +345,12 @@ const keyId = (req, res, next) => { @@ -345,6 +345,12 @@ const keyId = (req, res, next) => {
345 * 搜索品牌下的商品 345 * 搜索品牌下的商品
346 */ 346 */
347 const searchBrandGoods = (req, res, next) => { 347 const searchBrandGoods = (req, res, next) => {
  348 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  349 + req.headers.origin : req.protocol + '://' + req.headers.host;
  350 +
  351 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  352 + res.setHeader('Access-Control-Allow-Credentials', 'true');
  353 +
348 co(function* () { 354 co(function* () {
349 let goodListApi = yield searchModel.getBrandGoods(req.query); 355 let goodListApi = yield searchModel.getBrandGoods(req.query);
350 356
@@ -367,6 +373,12 @@ const searchBrandGoods = (req, res, next) => { @@ -367,6 +373,12 @@ const searchBrandGoods = (req, res, next) => {
367 * 搜索店铺下的商品 373 * 搜索店铺下的商品
368 */ 374 */
369 const searchShopGoods = (req, res, next) => { 375 const searchShopGoods = (req, res, next) => {
  376 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  377 + req.headers.origin : req.protocol + '://' + req.headers.host;
  378 +
  379 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  380 + res.setHeader('Access-Control-Allow-Credentials', 'true');
  381 +
370 co(function* () { 382 co(function* () {
371 let goodListApi = yield searchModel.getShopGoods(req.query); 383 let goodListApi = yield searchModel.getShopGoods(req.query);
372 384