url-rewrite.js 2.87 KB
/**
 * URL 重写(主要用于兼容原来PHP的连接)
 */

const helpers = global.yoho.helpers;

module.exports = () => {
    return (req, res, next) => {
        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 (/^\/sale/.test(req.url)) {
            // sale 兼容php的url
            res.redirect(301, helpers.urlFormat('/product/sale', req.query, 'default'));
            return;
        }

        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) || /\/so\/(.*).html/.test(req.url)) {
            // 获取seo兼容
            req.url = `/product/search${req.path}`;
        }

        if (/^\/shop/.test(req.url)) {
            // SEO 店铺路由重写 新路由
            req.url = `/product/${req.url}`;
        }

        if (/^\/list/.test(req.url)) {
            // 列表页路由重写 跳转到新的列表路由,进行参数的前置处理
            req.url = `/product/${req.url}`;
        }

        if (/^\/boys-new/.test(req.url)) {
            req.url = '/product/boys-new/';
        }

        if (/^\/girls-new/.test(req.url)) {
            req.url = '/product/girls-new/';
        }

        if (/^\/kids-new/.test(req.url)) {
            req.url = '/product/kids-new/';
        }

        if (/^\/lifestyle-new/.test(req.url)) {
            req.url = '/product/lifestyle-new/';
        }

        next();
    };
};