app.js
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'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, '');
// 全局注册library
yohoLib.global(config);
global.yoho.redis = require('./libs/redis');
const logger = global.yoho.logger;
const app = express();
const seo = require('./apps/seo');
const cseo = require('./apps/controllers/seo/index');
// 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('/dist', express.static(path.join(__dirname, './public/dist/')));
// 添加请求上下文
app.use(global.yoho.httpCtx());
app.get('/goods-:start.xml', cseo.index);
app.get('/auto-goods.html', cseo.autoGoodsXml);
app.get('/seo/setTask', cseo.setTask);
app.get('/seo/delTask', cseo.delTask);
app.get('/seo/sitemap.xml', cseo.siteMapXml);
app.get('/demo.xml', cseo.demoXml);
// 定时任务 主动推送和生成xml
seo.start();
// seo.sendKeywordsUrls();
app.get('/synchronousKeywords', seo.synchronousKeywords);
app.get('/sendKeywordsUrls', seo.sendKeywordsUrls);
app.get('/sendUrls', seo.sendUrls);
app.listen(config.port, function() {
logger.info(`yoho seo start : http://127.0.0.1:${config.port}`);
});