www.js 6.07 KB
/**
 * Created by TaoHuang on 2017/2/22.
 */

'use strict';

// const _ = require('lodash');

const helpers = global.yoho.helpers;
const TYPE = require('../type');
const MOBILE_DOMAIN = '//guang.m.yohobuy.com';

module.exports = [
    {
        type: TYPE.redirect,
        origin: /^\/product\/sale(\/|())\?channel=(.*)/,
        target: (req) => {
            let channel = req.query.channel || req.yoho.channel;

            return helpers.urlFormat(`/${channel}-sale/`);
        }
    },
    {
        type: TYPE.redirect,
        origin: /^\/product\/(boys|girls|kids|lifestyle)-sale(.*)$/,
        target: (req, match, channel, url) => {
            return helpers.urlFormat(`/${channel}-sale${url}`);
        }
    },
    {
        type: TYPE.redirect,
        origin: /^\/product\/sale\/(vip|breakingYards|newSale|discount)(.*)$/,
        target: (req, match, type) => {
            let channel = req.query.channel || req.yoho.channel;

            if (type === 'discount') {
                type += `/id${req.query.id}`;
            }

            return helpers.urlFormat(`/${channel}-sale/${type}`);
        }
    },
    {
        type: TYPE.redirect,
        origin: '/product/sale/?msort=10',
        target: helpers.urlFormat('/product/lifestyle-sale/')
    },

    // 商品详情页老链接,形试一
    {
        type: TYPE.redirect,
        origin: /^\/product\/pro_([\d]+)_([\d]+)\/(.*).html(.*)/,
        target: (req, match, p1, p2, p3, p4) => helpers.urlFormat(`/p${p1}.html${p4}`, null, 'item')
    },

    // 商品详情页老链接,形式二
    {
        type: TYPE.redirect,
        origin: /^\/product\/pro_([\d]+)(.*)/,
        target: (req, match, p1) => helpers.urlFormat(`/p${p1}.html`, null, 'item')
    },

    // 商品详情页新链接
    {
        type: TYPE.redirect,
        origin: /^\/p([\d]+)(.*)/,
        target: req => helpers.urlFormat(req.url, null, 'item')
    },

    // 品牌一览
    {
        type: TYPE.redirect,
        origin: /\/brands\?.*channel=(boys|girls|kids|lifestyle)/,
        target: (req) => {
            return helpers.urlFormat(
                `/${req.query.channel}-brands/`,
                null,
                'www'
            );
        }
    },

    // 品牌一览专题
    {
        type: TYPE.redirect,
        origin: (req) => req.path === '/brands/plusstar',
        target: (req) => {
            return helpers.urlFormat(
                `/${req.query.channel}-brands/plusstar/id${req.query.id || 0}-p${req.query.page || 1}/`,
                null,
                'www'
            );
        }
    },

    // 推荐词列表页
    {
        type: TYPE.rewrite,
        origin: /^\/so\/(.*)\.html(.*)/,
        target: (req, match, p1) => `/product/search/keyword/${p1}`
    },

    // 推荐词id列表页
    {
        type: TYPE.rewrite,
        origin: /^\/chanpin\/(.*)\.html(.*)/,
        target: (req, match, p1) => `/product/search/chanpin/${p1}`
    },

    // erp2good
    {
        type: TYPE.rewrite,
        origin: (req) => {
            return req.path === '/erp2goods';
        },
        target: '/common/erp2goods'
    },
    {
        type: TYPE.redirect,
        origin: '/index.html',
        target: helpers.urlFormat('/')
    },

    // 新品到着
    {
        type: TYPE.rewrite,
        origin: /^\/(boys|girls|kids|lifestyle)-new/,
        target: (req, match, channel) => {
            req.pathChannel = channel;
            return '/product/list/new';
        }
    },

    // 逛

    // 首页
    {
        type: TYPE.rewrite,
        origin: /^\/guang\/(boys|girls|kids|lifestyle)(\/*)$/,
        target: (req, match, channel) => {
            req.query.channel = channel;
            return `/guang/?chanel=${channel}`;
        }
    },

    // 首页 + 类型
    {
        type: TYPE.rewrite,
        origin: /^\/guang\/(boys|girls|kids|lifestyle)-t([\d]+)(\/*)$/,
        target: (req, match, channel, type) => {
            req.query.channel = channel;
            req.query.type = type;
            return `/guang/?chanel=${channel}&type=${type}`;
        }
    },

    // 列表页 + 类型 + 翻页
    {
        type: TYPE.rewrite,
        origin: /^\/guang\/(boys|girls|kids|lifestyle)-t([\d]+)-p([\d]+)(\/*)$/,
        target: (req, match, channel, type, page) => {
            req.query.channel = channel;
            req.query.type = type;
            req.query.page = page;
            return `/guang/index/index/?type=${type}&channel=${page}`;
        }
    },

    // 编缉首页
    {
        type: TYPE.rewrite,
        origin: /^\/guang\/author-(boys|girls|kids|lifestyle)-([\d]+)(\/*)$/,
        target: (req, match, channel, authorId) => {
            req.query.channel = channel;
            req.query.author_id = authorId;
            req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}/`;
            return `/guang/index/editor?channel=${channel}&author_id=${authorId}`;
        }
    },

    // 编缉首页 + 翻页
    {
        type: TYPE.rewrite,
        origin: /^\/guang\/author-(boys|girls|kids|lifestyle)-([\d]+)-p([\d]+)(\/*)$/,
        target: (req, match, channel, authorId, page) => {
            req.query.channel = channel;
            req.query.author_id = authorId;
            req.query.page = page;
            req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}-p${page}/`;
            return `/guang/index/editor?channel=${channel}&author_id=${authorId}&page=${page}`;
        }
    },

    // sale页
    {
        type: TYPE.rewrite,
        origin: /^\/(boys|girls|kids|lifestyle)-sale(.*)$/,
        target: (req, match, channel, url) => {
            req.query.channel = channel;
            return `/product/sale${url}`;
        }
    },
    {
        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';
        }
    },
    // {
    //     type: TYPE.rewrite,
    //     origin: /^\/(list|search|new|sale|shop)((\/|\?)(.*)|())$/,
    //     target: (req) => {
    //         return `/product${req.url}`;
    //     }
    // },
];