Authored by yyq

htaccess

... ... @@ -4,6 +4,24 @@
'use strict';
module.exports = [
const helpers = global.yoho.helpers;
const TYPE = require('../type');
module.exports = [
{
type: TYPE.redirect,
origin: /\/about?shopId=([\d]+)/,
target: (req, match, id) => {
return helpers.urlFormat(`/shop${id}-about`, {}, req.subdomains[0]);
}
},
{
type: TYPE.rewrite,
origin: /\/shop([\d]+)-about/,
target: (req, match, id) => {
req.query.domain = req.subdomains[0];
req.query.shopId = id;
return '/product/index/about';
}
}
];
... ...
/**
* Created by YanQing.Yang on 2017/3/9.
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const mapSort = require(`${global.utils}/map-sort`);
const TYPE = require('../type');
module.exports = [
// 老版newURL
{
type: TYPE.redirect,
origin: '/new?gender=1,3&order=s_t_desc&msort=1,3,4,6,7,8,308,360',
target: helpers.urlFormat('/boys-new', {}, 'list')
},
{
type: TYPE.redirect,
origin: '/new?gender=2,3&order=s_t_desc&msort=1,3,4,6,7,8,308,360',
target: helpers.urlFormat('/girls-new', {}, 'list')
},
{
type: TYPE.redirect,
origin: '/new?order=s_t_desc&msort=365',
target: helpers.urlFormat('/kids-new', {}, 'list')
},
{
type: TYPE.redirect,
origin: '/new?order=s_t_desc&msort=10',
target: helpers.urlFormat('/lifestyle-new', {}, 'list')
},
// 筛选参数排序匹配
{
type: TYPE.redirect,
origin: req => {
if (_.isEmpty(req.query)) {
return false;
}
let sorts = mapSort(req.query);
let queryKeys = _.keys(req.query);
let index = 0;
let matched = _.map(sorts, (val, key) => {
return key === queryKeys[index++];
});
if (_.every(matched, match => match)) {
return false;
}
return true;
},
target: req => helpers.urlFormat(req.path, mapSort(req.query), 'list')
},
{
type: TYPE.rewrite,
origin: req => {
return !req.path || req.path === '/';
},
target: '/product/list/index'
},
{
type: TYPE.rewrite,
origin: /\/(.*)-new/,
target: (req, match, channel) => {
return `/product/list/${channel}-new`;
}
},
{
type: TYPE.rewrite,
origin: req => req.path === '/new',
target: '/product/list/new'
}
];
... ...
... ... @@ -52,8 +52,6 @@ module.exports = () => {
{ // eslint-disable-line
if (!req.path || req.path === '/') {
req.url = '/product/list/index';
} else if (/\/(.*)-new/.exec(req.path) !== null) {
req.url = `/product/list/${RegExp.$1}-new`;
} else if (req.path === '/new') {
req.url = '/product/list/new';
}
... ... @@ -74,9 +72,6 @@ module.exports = () => {
req.url = `/product/index/brand?domain=${req.subdomains[0]}`;
} else if (req.path === '/about') {
req.url = `/product/index/about?domain=${req.subdomains[0]}`;
} else if (/\/shop([\d]+)-about/.exec(req.path) !== null) {
req.query.shopId = RegExp.$1;
req.url = '/product/index/about';
}
break;
}
... ...
/**
* 参数排序
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2017/3/9
*/
'use strict';
/**
* 对象字段排序
*/
module.exports = obj => {
if (!obj) {
return {};
}
let data = {};
Object.keys(obj).sort().forEach(k => {
data[k] = obj[k];
});
return data;
};
... ...