Showing
4 changed files
with
119 additions
and
6 deletions
@@ -4,6 +4,24 @@ | @@ -4,6 +4,24 @@ | ||
4 | 4 | ||
5 | 'use strict'; | 5 | 'use strict'; |
6 | 6 | ||
7 | -module.exports = [ | 7 | +const helpers = global.yoho.helpers; |
8 | +const TYPE = require('../type'); | ||
8 | 9 | ||
10 | +module.exports = [ | ||
11 | + { | ||
12 | + type: TYPE.redirect, | ||
13 | + origin: /\/about?shopId=([\d]+)/, | ||
14 | + target: (req, match, id) => { | ||
15 | + return helpers.urlFormat(`/shop${id}-about`, {}, req.subdomains[0]); | ||
16 | + } | ||
17 | + }, | ||
18 | + { | ||
19 | + type: TYPE.rewrite, | ||
20 | + origin: /\/shop([\d]+)-about/, | ||
21 | + target: (req, match, id) => { | ||
22 | + req.query.domain = req.subdomains[0]; | ||
23 | + req.query.shopId = id; | ||
24 | + return '/product/index/about'; | ||
25 | + } | ||
26 | + } | ||
9 | ]; | 27 | ]; |
doraemon/middleware/htaccess/rules/list.js
0 → 100644
1 | +/** | ||
2 | + * Created by YanQing.Yang on 2017/3/9. | ||
3 | + */ | ||
4 | + | ||
5 | +'use strict'; | ||
6 | + | ||
7 | +const _ = require('lodash'); | ||
8 | +const helpers = global.yoho.helpers; | ||
9 | +const mapSort = require(`${global.utils}/map-sort`); | ||
10 | +const TYPE = require('../type'); | ||
11 | + | ||
12 | +module.exports = [ | ||
13 | + // 老版newURL | ||
14 | + { | ||
15 | + type: TYPE.redirect, | ||
16 | + origin: '/new?gender=1,3&order=s_t_desc&msort=1,3,4,6,7,8,308,360', | ||
17 | + target: helpers.urlFormat('/boys-new', {}, 'list') | ||
18 | + }, | ||
19 | + { | ||
20 | + type: TYPE.redirect, | ||
21 | + origin: '/new?gender=2,3&order=s_t_desc&msort=1,3,4,6,7,8,308,360', | ||
22 | + target: helpers.urlFormat('/girls-new', {}, 'list') | ||
23 | + }, | ||
24 | + { | ||
25 | + type: TYPE.redirect, | ||
26 | + origin: '/new?order=s_t_desc&msort=365', | ||
27 | + target: helpers.urlFormat('/kids-new', {}, 'list') | ||
28 | + }, | ||
29 | + { | ||
30 | + type: TYPE.redirect, | ||
31 | + origin: '/new?order=s_t_desc&msort=10', | ||
32 | + target: helpers.urlFormat('/lifestyle-new', {}, 'list') | ||
33 | + }, | ||
34 | + | ||
35 | + // 筛选参数排序匹配 | ||
36 | + { | ||
37 | + type: TYPE.redirect, | ||
38 | + origin: req => { | ||
39 | + if (_.isEmpty(req.query)) { | ||
40 | + return false; | ||
41 | + } | ||
42 | + | ||
43 | + let sorts = mapSort(req.query); | ||
44 | + let queryKeys = _.keys(req.query); | ||
45 | + let index = 0; | ||
46 | + let matched = _.map(sorts, (val, key) => { | ||
47 | + return key === queryKeys[index++]; | ||
48 | + }); | ||
49 | + | ||
50 | + if (_.every(matched, match => match)) { | ||
51 | + return false; | ||
52 | + } | ||
53 | + | ||
54 | + return true; | ||
55 | + }, | ||
56 | + target: req => helpers.urlFormat(req.path, mapSort(req.query), 'list') | ||
57 | + }, | ||
58 | + { | ||
59 | + type: TYPE.rewrite, | ||
60 | + origin: req => { | ||
61 | + return !req.path || req.path === '/'; | ||
62 | + }, | ||
63 | + target: '/product/list/index' | ||
64 | + }, | ||
65 | + { | ||
66 | + type: TYPE.rewrite, | ||
67 | + origin: /\/(.*)-new/, | ||
68 | + target: (req, match, channel) => { | ||
69 | + return `/product/list/${channel}-new`; | ||
70 | + } | ||
71 | + }, | ||
72 | + { | ||
73 | + type: TYPE.rewrite, | ||
74 | + origin: req => req.path === '/new', | ||
75 | + target: '/product/list/new' | ||
76 | + } | ||
77 | +]; |
@@ -52,8 +52,6 @@ module.exports = () => { | @@ -52,8 +52,6 @@ module.exports = () => { | ||
52 | { // eslint-disable-line | 52 | { // eslint-disable-line |
53 | if (!req.path || req.path === '/') { | 53 | if (!req.path || req.path === '/') { |
54 | req.url = '/product/list/index'; | 54 | req.url = '/product/list/index'; |
55 | - } else if (/\/(.*)-new/.exec(req.path) !== null) { | ||
56 | - req.url = `/product/list/${RegExp.$1}-new`; | ||
57 | } else if (req.path === '/new') { | 55 | } else if (req.path === '/new') { |
58 | req.url = '/product/list/new'; | 56 | req.url = '/product/list/new'; |
59 | } | 57 | } |
@@ -74,9 +72,6 @@ module.exports = () => { | @@ -74,9 +72,6 @@ module.exports = () => { | ||
74 | req.url = `/product/index/brand?domain=${req.subdomains[0]}`; | 72 | req.url = `/product/index/brand?domain=${req.subdomains[0]}`; |
75 | } else if (req.path === '/about') { | 73 | } else if (req.path === '/about') { |
76 | req.url = `/product/index/about?domain=${req.subdomains[0]}`; | 74 | req.url = `/product/index/about?domain=${req.subdomains[0]}`; |
77 | - } else if (/\/shop([\d]+)-about/.exec(req.path) !== null) { | ||
78 | - req.query.shopId = RegExp.$1; | ||
79 | - req.url = '/product/index/about'; | ||
80 | } | 75 | } |
81 | break; | 76 | break; |
82 | } | 77 | } |
utils/map-sort.js
0 → 100644
1 | +/** | ||
2 | + * 参数排序 | ||
3 | + * @author: yyq<yanqing.yang@yoho.cn> | ||
4 | + * @date: 2017/3/9 | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +/** | ||
10 | + * 对象字段排序 | ||
11 | + */ | ||
12 | +module.exports = obj => { | ||
13 | + if (!obj) { | ||
14 | + return {}; | ||
15 | + } | ||
16 | + let data = {}; | ||
17 | + | ||
18 | + Object.keys(obj).sort().forEach(k => { | ||
19 | + data[k] = obj[k]; | ||
20 | + }); | ||
21 | + | ||
22 | + return data; | ||
23 | +}; |
-
Please register or login to post a comment