-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.ts
executable file
·36 lines (30 loc) · 1012 Bytes
/
app.ts
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
/// <reference path="./typings/tsd.d.ts"/>
import * as Koa from 'koa';
import * as bodyParser from 'koa-bodyparser';
import * as koaLogger from 'koa-logger';
import logger from './utils/logger';
import * as serve from 'koa-static';
import * as cors from 'koa2-cors';
import * as path from 'path';
import rank from './routes/rank';
import news from './routes/news';
import analytics from './routes/analytics';
import summarize from './routes/summarize';
import { crawlJob } from './database/crawler';
const app = new Koa();
const port = process.env.PORT || 3000;
const dist = path.join(__dirname, '..', 'public');
const bpOption = { extendTypes: { json: ['application/x-javascript'] } };
app
.use(koaLogger())
.use(bodyParser(bpOption))
.use(cors())
.use(rank.routes())
.use(analytics.routes())
.use(news.routes())
.use(summarize.routes())
.use(serve(dist));
if (process.argv[2] === '--with-crawler') {
crawlJob.start();
}
app.listen(port, () => logger.info(`Listening on PORT ${port}`));