-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
40 lines (33 loc) · 810 Bytes
/
app.js
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
const Koa = require('koa');
const path = require('path');
const static = require('koa-static');
const views = require('koa-views');
const utils = require('./utils/util');
const timeJob = require('./utils/timeJob');
const CrawlerCtr = require('./controllers/crawler');
const config = require('./config');
const app = new Koa();
const crawler = new CrawlerCtr();
// 静态文件
app.use(static(
path.join( __dirname, './static')
))
// 加载模板引擎
app.use(views(
path.join(__dirname, './views'), {
extension: 'ejs'
}
))
app.use(async ctx => {
let list = await crawler.getNews();
await ctx.render('index', {
list,
time: utils.getNowDate()
})
});
app.listen(config.port, () => {
console.log('开始监听' + config.port)
timeJob(function() {
crawler.cnNews();
})
});