app.js 2.73 KB
'use strict';

const path = require('path');
const express = require('express');
const hbs = require('express-handlebars');
const config = require('./config/config');
const yohoLib = require('yoho-node-lib');

// set root path
global.ROOT_PATH = path.join(__dirname, '');
global.Promise = require('bluebird');

// 全局注册library
yohoLib.global(config);
global.yoho.redis = require('./libs/redis');
const logger = global.yoho.logger;
const app = express();
const cseo = require('./apps/controllers/seo/index');
const baiduXzh = require('./apps/controllers/seo/xzh');

// hbs-set
app.engine('hbs', hbs({
    extname: '.hbs',
    defaultLayout: 'layout',
    layoutsDir: path.join(__dirname, 'hbs'),
    partialsDir: path.join(__dirname, 'hbs/partials'),
    views: path.join(__dirname, 'apps/views')
}));

// set-express-view
app.set('views', path.join(__dirname, 'apps/views'));
app.set('view engine', 'hbs');

// 设置public文件夹为存放静态文件的目录
app.use('/xml-data/goods-xml', express.static(path.join(__dirname, './public/dist/goods-xml/')));

// 添加请求上下文
app.use(global.yoho.httpCtx());

app.get('/xml-data/goods-:start.xml', cseo.index);
app.get('/xml-data/auto-goods.html', cseo.autoGoodsXml);
app.get('/xml-data/goods/sitemap.xml', cseo.siteMapXml);
app.get('/xml-data/demo.xml', cseo.demoXml);
app.get('/xml-data/demo.xsd', cseo.demoXsd);

app.get('/setTask', cseo.setTask);
app.get('/delTask', cseo.delTask);

// 百度熊掌号
app.get('/sendXzh', baiduXzh.index);

// 百度熊掌号-潮流全站推送一遍mip
app.get('/xzh-yohoGirlsAll', baiduXzh.yohoGirlsAll);

// 百度熊掌号--潮流全站推送一遍mip
app.get('/xzh-yohoBoysAll', baiduXzh.yohoBoysAll);

// 百度熊掌号--mars全站推送一遍mip
app.get('/xzh-marsAll', baiduXzh.marsAll);

// 百度熊掌号--yohoBoysReal实时推送mip
app.get('/xzh-yohoBoysReal', baiduXzh.yohoBoysReal);

// 百度熊掌号--mars实时推送mip
app.get('/xzh-marsReal', baiduXzh.marsReal);

// 商品详情-百度链接提交
app.get('/goodsUrl', cseo.goodsUrl);

// 逛详情-百度链接提交
app.get('/guangUrl', cseo.guangUrl);

// 潮流首页-百度链接提交
app.get('/yohoBoysUrl', cseo.yohoBoysUrl);

// 潮流首页-百度链接提交
app.get('/yohoGirlsUrl', cseo.yohoGirlsUrl);

// 潮流获取sitemap连接,设置到redis
app.get('/newsSitemap', cseo.newsSitemap);

// mars全站推送一遍mip和百度资源位
app.get('/marsAll', cseo.marsAll);

// mars实时推送百度资源位连接和百度资源位mip
app.get('/marsReal', cseo.marsReal);

// docker验证项目是否正常发布
app.use('/node/status.html', (req, res) => {
    return res.status(204).end();
});

app.listen(config.port, function() {
    logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
});