url-rewrite.js
2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* URL 重写(主要用于兼容原来PHP的连接)
*/
const stringProcess = require('./../../utils/string-process');
module.exports = () => {
return (req, res, next) => {
req.url = stringProcess.decodeURIComponent(req.url) || '/404';// 错误的网址编码重定向404
if (/^\/home\/orders\/paynew/.test(req.url)) {
// 支付中心,由于微信安全配置限制在 home/orders 路径下,需要转发,误删!!!
req.url = `/cart${req.url}`;
}
if (/^\/coupon\/floor/.test(req.url)) {
// 领券中心 兼容php的url
req.url = `/activity${req.url}`;
}
if (/^\/shopping\/pay\/aliwapreturn/.test(req.url)) {
// 兼容php的url
req.url = `/cart${req.url}`;
}
if (/^\/help\/limitcodeIntro/.test(req.url)) {
// 什么是限购码 兼容PHP的url
req.url = '/service/limitcodeIntro';
}
if (/^\/help\/limitcodeColSize/.test(req.url)) {
// 选择限购码颜色和尺寸 兼容PHP的url
req.url = '/service/limitcodeColSize';
}
if (/^\/help\/limitcodeHelp/.test(req.url)) {
// 如何获得限购码 兼容PHP的url
req.url = '/service/limitcodeHelp';
}
if (/^\/help\/shareorder\.html/.test(req.url)) {
// 晒单 兼容PHP的url
req.url = '/service/shareorder';
}
if (/^\/index\/systemUpdate/.test(req.url)) {
// 升级公告 兼容PHP的url
req.url = '/service/systemUpdate';
}
if (/^\/sitemap(\d*)\.xml/.test(req.url)) {
// sitemap/sitemap.xml
req.url = `/service${req.url}`;
}
if (/^\/coupon\/couponSend/.test(req.url)) {
// 获取优惠券 兼容php的url
req.url = '/activity/couponSend';
}
if (/^\/chanpin\/(.*).html/.test(req.url)) {
// 获取seo兼容
req.url = `/product/search${req.path}`;
}
if (/^\/(list|shop)/.test(req.url)) {
// 商品列表页、全球购商品列表页、店铺首页路由
req.url = `/product${req.url}`;
}
if (/^\/(boys|girls|kids|lifestyle)-/.test(req.url)) {
// 匹配新品到着,sale 带频道的路由
req.url = `/product${req.url}`;
}
if (/^\/search/.test(req.url)) {
// 搜索
req.url = `/product${req.url}`;
}
next();
};
};