-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (33 loc) · 832 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
41
const Koa = require('koa');
const Favicon = require('koa-favicon');
const Render = require('koa-ejs');
const Router = require('koa-router');
const Serve = require('koa-static');
const crawler = require('./lib/crawler/zenlogic');
const app = new Koa();
const router = new Router();
let users = [];
Render(app, {
root: __dirname + '/views',
layout: 'template',
viewExt: 'html',
cache: false,
debug: true,
});
app.use(Serve(__dirname + '/views'));
router.get('/', async (ctx, next) => {
if (users.length == 0) {
users = await crawler();
}
await next();
await ctx.render('content', {
users,
});
});
app.use(router.routes());
app.use(router.allowedMethods());
app.use(Favicon(__dirname + '/favicon.ico'));
app.listen(process.env.PORT || 3000);
if (!process.env.DYNO) {
require('dotenv').config();
}