forked from zgq354/weibo-rss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
30 lines (23 loc) · 727 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
const Koa = require('koa');
const serve = require('koa-static');
const router = require('./core/router');
const logger = require('./core/logger');
const app = new Koa();
// enable X-Forwarded-For
app.proxy = true;
// logger
app.use(async (ctx, next) => {
const startTime = Date.now();
logger.debug(`${ctx.req.method} ${ctx.originalUrl} ${ctx.ip}`);
await next();
logger.info(`[${ctx.status}] ${ctx.req.method} ${ctx.originalUrl} ${ctx.ip} ${Date.now() - startTime}ms`);
});
app.use(serve(__dirname + '/public'));
app.use(router.routes());
app.start = function (port) {
app.listen(port, function () {
logger.info(`weibo-rss start`);
logger.info(`Listening Port ${port}`);
});
};
module.exports = app;