Authored by 郭成尧

shop-seo

... ... @@ -19,16 +19,19 @@ const co = require('bluebird').coroutine;
const shop = {
rewrite(req, res, next) {
let pathParams = _.last(_.split(req.url.replace('.html', ''), '/'));
let shopId = _.last(_.split(pathParams, '-'));
if (_.isNumber(+shopId)) {
req.query.shop_id = shopId;
}
onlyDomain(req, res, next) {
req.query.domain = req.params.domain;
shop.entry(req, res, next);
},
req.query.domain = pathParams.replace(`-${shopId}`, '');
onlyShopId(req, res, next) {
req.query.shop_id = req.params[0];
shop.entry(req, res, next);
},
rewrite(req, res, next) {
req.query.domain = req.params.domain;
req.query.shop_id = req.params.shop_id;
shop.entry(req, res, next);
},
... ...
... ... @@ -168,7 +168,9 @@ router.get('/index/getBrandCouponsList', list.getBrandCouponsList);
// 店铺重构
router.get('/shop', newShop.entry); // 统一店铺入口
router.get('/shop/*', newShop.rewrite); // 统一店铺入口
router.get('/shop/:domain/:shop_id.html', newShop.rewrite); // 域名和店铺 ID 均存在
router.get(/^\/shop\/(\d+)\.html/, newShop.onlyShopId); // 只有店铺 ID 的情况
router.get('/shop/:domain.html', newShop.onlyDomain); // 只有域名的情况
router.get('/index/brand', newShop.entry); // 旧的路由,走到新的 controller
router.get('/index/brandFav', newShop.brandFav);
router.get('/new/shop/hotlist', newShop.shopHotList);
... ...
... ... @@ -74,7 +74,7 @@ module.exports = () => {
if (/^\/product\/shop/.test(req.url)) {
// 老路由 301 跳转到新路由
if (req.query.shop_id && req.query.domain) {
return res.redirect(301, `/shop/${req.query.domain}-${req.query.shop_id}.html`);
return res.redirect(301, `/shop/${req.query.domain}/${req.query.shop_id}.html`);
}
if (req.query.shop_id) {
... ...