Authored by 郭成尧

url-rewrite

@@ -11,6 +11,7 @@ const headerModel = require('../../../doraemon/models/header'); @@ -11,6 +11,7 @@ const headerModel = require('../../../doraemon/models/header');
11 const searchModel = require(`${mRoot}/search`); 11 const searchModel = require(`${mRoot}/search`);
12 const _ = require('lodash'); 12 const _ = require('lodash');
13 const helpers = global.yoho.helpers; 13 const helpers = global.yoho.helpers;
  14 +const stringProcess = require(`${utils}/string-process`);
14 const searchProcess = require(`${utils}/search-process`); 15 const searchProcess = require(`${utils}/search-process`);
15 const productProcess = require(`${utils}/product-process`); 16 const productProcess = require(`${utils}/product-process`);
16 const listParamsProcess = require(`${utils}/list-params-process`); 17 const listParamsProcess = require(`${utils}/list-params-process`);
@@ -206,6 +207,10 @@ exports.search = (req, res, next) => { @@ -206,6 +207,10 @@ exports.search = (req, res, next) => {
206 params.uid = uid; 207 params.uid = uid;
207 } 208 }
208 209
  210 + if (params.query) {
  211 + params.query = stringProcess.decodeURIComponent(params.query);
  212 + }
  213 +
209 params.isApp = req.yoho.isApp; 214 params.isApp = req.yoho.isApp;
210 params.limit = 24; 215 params.limit = 24;
211 216
@@ -141,14 +141,15 @@ router.get('/seckill/list', seckill.indexData); @@ -141,14 +141,15 @@ router.get('/seckill/list', seckill.indexData);
141 router.post('/seckill/remind', seckill.remind); // only app; 秒杀提醒 141 router.post('/seckill/remind', seckill.remind); // only app; 秒杀提醒
142 router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表根据活动id获取商品列表 142 router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表根据活动id获取商品列表
143 143
144 -router.get('/search/index', search.index); // 搜索主页 144 +router.get('/search', search.index); // 搜索主页
  145 +router.get('/search/list', rewrite.resolvePathParams, search.list); // 搜索落地页
  146 +router.get('/search/filter', rewrite.resolvePathParamsAjax, search.filter); // filter
  147 +router.get('/search/fuzzyDatas', search.fuzzyDatas); // fuzzyDatas
  148 +router.get('/search/search', rewrite.resolvePathParamsAjax, search.search); // ajax 请求商品数据
  149 +
145 router.get('/search/so/:query.html', rewrite.sortParams, chanpin.keyword); // 推广落地页 150 router.get('/search/so/:query.html', rewrite.sortParams, chanpin.keyword); // 推广落地页
146 router.get('/search/chanpin/:id.html', rewrite.sortParams, chanpin.keyId); 151 router.get('/search/chanpin/:id.html', rewrite.sortParams, chanpin.keyId);
147 router.get('/search/chanpin/goods', chanpin.searchGoods); // 搜索的商品 152 router.get('/search/chanpin/goods', chanpin.searchGoods); // 搜索的商品
148 -router.get('/search/list', rewrite.sortParams, search.list); // 搜索落地页  
149 -router.get('/search/filter', search.filter); // filter  
150 -router.get('/search/fuzzyDatas', search.fuzzyDatas); // fuzzyDatas  
151 -router.get('/search/search', search.search); // ajax 请求商品数据  
152 router.get('/search/brand/goods', search.searchBrandGoods); // 搜索品牌下的商品 153 router.get('/search/brand/goods', search.searchBrandGoods); // 搜索品牌下的商品
153 router.get('/search/shop/goods', search.searchShopGoods); // 搜索店铺下的商品 154 router.get('/search/shop/goods', search.searchShopGoods); // 搜索店铺下的商品
154 155
@@ -35,14 +35,14 @@ module.exports = () => { @@ -35,14 +35,14 @@ module.exports = () => {
35 35
36 // 有查询关键字 36 // 有查询关键字
37 if (_.keys(req.query).length) { 37 if (_.keys(req.query).length) {
38 - req.url = `/product/search/list?${querystring.stringify(req.query)}`; 38 + return res.redirect(301, listParamsProcess.generatePathUrl(req.query, 'search/list'));
39 } else { 39 } else {
40 - req.url = `/product/search/index?${querystring.stringify(req.query)}`; 40 + req.url = '/search';
41 } 41 }
42 } 42 }
43 43
44 if (req.path === '/search') { 44 if (req.path === '/search') {
45 - req.url = `/product/search/index?${querystring.stringify(req.query)}`; 45 + return res.redirect(301, listParamsProcess.generatePathUrl(req.query, 'search/list'));
46 } 46 }
47 break; 47 break;
48 48
@@ -73,6 +73,11 @@ module.exports = () => { @@ -73,6 +73,11 @@ module.exports = () => {
73 req.url = `/product${req.url}`; 73 req.url = `/product${req.url}`;
74 } 74 }
75 75
  76 + if (/^\/search/.test(req.url)) {
  77 + // 搜索
  78 + req.url = `/product${req.url}`;
  79 + }
  80 +
76 next(); 81 next();
77 }; 82 };
78 }; 83 };