-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
31 lines (24 loc) · 921 Bytes
/
index.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
'use strict';
require('./lib/configure');
const koa = require('koa');
const koaPino = require('koa-pino-logger');
const responseTime = require('koa-response-time');
const gaPageview = require('koa-ga-pageview');
const error = require('./lib/middleware/error');
const notFound = require('./lib/middleware/not-found');
const route = require('./lib/route');
module.exports = (config, esClient) => {
const app = koa();
const log = logger.child({ module: 'index' });
// Middleware
app.use(responseTime());
app.use(error());
app.use(notFound());
app.use(koaPino({ name: 'npms-badges', level: logger.level, serializers: logger.serializers }));
config.googleAnalyticsId && app.use(gaPageview(config.googleAnalyticsId, '_ga'));
// App route handler
app.use(route(config, esClient));
// Log errors
app.on('error', (err) => log.error({ err }, err.message));
return app;
};