Authored by 郭成尧

old-url-301

'use strict';
const utils = '../../../utils';
const headerModel = require('../../../doraemon/models/header');
const model = require('../models/global');
const _ = require('lodash');
const listParamsProcess = require(`${utils}/list-params-process`);
/**
* 旧路由 301 跳转
*/
const redirect = (req, res) => {
let pathParamsUrl = listParamsProcess.generatePathUrl(req.query, 'list/global');
return res.redirect(301, pathParamsUrl);
};
const list = (req, res, next) => {
let brand = req.query.brand;
... ... @@ -130,5 +141,6 @@ module.exports = {
list,
search,
detail,
gethtml
gethtml,
redirect
};
... ...
... ... @@ -6,11 +6,11 @@
'use strict';
const mRoot = '../models';
// const cookie = require(`${library}/cookie`);
const utils = '../../../utils';
const headerModel = require('../../../doraemon/models/header');
const saleModel = require(`${mRoot}/sale`);
const qs = require('querystring');
const _ = require('lodash');
const listParamsProcess = require(`${utils}/list-params-process`);
const channelToAppChannel = (channel) => {
return {
... ... @@ -119,12 +119,10 @@ let index = (req, res, next) => {
// 301到新路由
let indexRedirect = (req, res) => {
let param = qs.stringify(req.query);
let pathParamsUrl = listParamsProcess.generatePathUrl(req.query, req.path);
let urlPath = _.replace(pathParamsUrl, '//m.yohobuy.com/sale', `//m.yohobuy.com/${req.yoho.channel}-sale`);
if (param) {
param = '?' + param;
}
res.redirect(301, `/product/${req.yoho.channel}-sale/${param}`);
return res.redirect(301, urlPath);
};
/**
... ...
... ... @@ -103,6 +103,7 @@ router.post('/detail/consultupvote', detail.consultUpvoteOrUseful); // 商品咨
router.post('/detail/consultuseful', detail.consultUpvoteOrUseful); // 商品咨询提交接口
router.get('/sale', rewrite.channel, sale.indexRedirect);
router.get('/sale/((breakingYards)?(vip)?(discount(/detail)?)?)', rewrite.channel, sale.indexRedirect);
router.get('/:channel-sale/discount/detail(/:pathParams)?',
rewrite.resolve,
... ... @@ -117,6 +118,7 @@ router.get('/:channel-sale/vip(/:pathParams)?',
rewrite.resolvePathParams,
sale.vip);
router.get('/:channel-sale/', rewrite.resolve, sale.index);
router.get('/:channel-sale/discount', rewrite.resolve, sale.discount);
router.get('/sale/discount', sale.discount);
router.get('/sale/discount/detail', sale.discountDetail);
... ... @@ -209,7 +211,7 @@ router.post('/bundle/cart/add', bundle.addToCart); // 套装加入购物车
router.post('/opt/favoriteProduct', newDetail.favoriteProduct); // 商品收藏、取消收藏
router.get('/detail/limitHelp', newDetail.limitHelp);
router.get('/global/list', globalPro.list); // 全球购列表页
router.get('/global/list', globalPro.redirect); // 全球购列表页
router.get('/global/search', rewrite.resolvePathParamsAjax, globalPro.search); // 全球购列表页搜索数据
router.get(/^\/global\/(\d+)\.html/, globalPro.detail); // 全球购店铺详情页
router.get('/global/gethtml', globalPro.gethtml); // 全球购商品信息
... ...
/**
* URL 重写(主要用于兼容原来PHP的连接)
*/
const helpers = global.yoho.helpers;
module.exports = () => {
return (req, res, next) => {
if (/^\/home\/orders\/paynew/.test(req.url)) {
... ... @@ -21,12 +18,6 @@ module.exports = () => {
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';
... ...
... ... @@ -90,7 +90,7 @@ const generatePathUrl = (queryParams, path) => {
pathUrl += noFindParams.length ? '?' + noFindParams.join('&') : '';
pathUrl = (pathUrl && !_.startsWith(pathUrl, '?')) ? `/${pathUrl}` : pathUrl;
return `${config.subDomains.default}/${path || 'list'}${pathUrl}`;
return `${config.subDomains.default}/${_.trim(path, '/') || 'list'}${pathUrl}`;
};
module.exports = {
... ...