Authored by yyq

shop url

'use strict';
const _ = require('lodash');
const mRoot = '../models';
const shopModel = require(`${mRoot}/shop-service`);
const tdk = require('../../../utils/getTDK');
... ... @@ -9,9 +10,12 @@ const tdk = require('../../../utils/getTDK');
exports.index = (req, res, next) => {
let domain = req.query.domain;
let shopId = req.query.shopId;
let shopInfo = req.params.shopInfo;
if (!domain) {
return next();
if (shopInfo) {
shopId = _.last(_.split(shopInfo, '-'));
domain = shopInfo.replace(`-${shopId}`, '');
req.query.shopId = shopId;
}
if (req.xhr && req.query._pjax && shopId) {
... ...
... ... @@ -122,6 +122,7 @@ router.post('/index/isFavoriteBrand', list.isFavoriteBrand); // 判断用户是
router.post('/index/getNodeContent', list.getNodeContent); // 品牌页水牌
router.post('/index/getAdnav', list.getAdnav); // 品牌页系列
router.get('/shop', shop.index); // 店铺首页
router.get('/shop/:shopInfo.html', shop.index); // 店铺首页
router.get('/shoplist', shop.list); // 店铺列表页
router.get('/shop/article', shop.article); // 店铺推荐文章
router.post('/shop/togglecollect', favorite.collectShop); // 店铺收藏
... ...
... ... @@ -205,5 +205,14 @@ module.exports = [
req.mobileUrl = `${MOBILE_DOMAIN}/author-${channel}-${authorId}-p${page}/`;
return `/guang/index/editor?channel=${channel}&author_id=${authorId}&page=${page}`;
}
},
// 店铺页
{
type: TYPE.rewrite,
origin: /^\/shop\/(.*)\.html(.*)$/,
target: (req) => {
return `/product${req.url}`;
}
}
];
... ...
... ... @@ -5,6 +5,9 @@
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
module.exports = () => {
return (req, res, next) => {
if (req.subdomains.length) {
... ... @@ -67,12 +70,8 @@ module.exports = () => {
}
default: // 其它(识别为店铺)
{ // eslint-disable-line
req.query.domain = req.subdomains[0];
if (!req.path || req.path === '/') {
req.url = '/product/shop';
}
break;
return res.redirect(301, helpers.urlFormat(`/shop/${req.subdomains[0]}-${req.query.shopId || ''}.html`, // eslint-disable-line
_.isEmpty(req.query) ? null : req.query));
}
}
}
... ...