-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (29 loc) · 1.19 KB
/
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
32
33
34
35
'use strict'
const conf = require('./lib/config')
const Koa = require('koa')
const Router = require('koa-router')
const bodyParser = require('koa-bodyparser')
const DataSources = require('./lib/data-sources')
const Controller = require('./lib/controller')
const logger = require('loglevel') // https://github.com/pimterry/loglevel
.getLogger(conf.appName)
logger.setLevel(conf.logLevel)
const app = new Koa()
const router = new Router()
const ds = new DataSources(conf.dataSourceTargets)
const c = new Controller(ds)
router
.get('/', c.getPingHandle())
.post('/search', c.postSearchHandle())
.post('/query', c.postQueryHandle())
.post('/annotations', c.postDumbHandle())
.post('/tag-keys', c.postDumbHandle())
.post('/tag-values', c.postDumbHandle())
app.use(bodyParser())
.use(async (ctx, next) => {
logger.debug(ctx.request.method, ctx.request.url, JSON.stringify(ctx.request.query), ctx.request.body)
await next() /* eslint callback-return: "off" */
})
.use(router.middleware())
.listen(parseInt(conf.port, 10),
() => logger.info(`Start 0.0.0.0:${conf.port}`, '[', router.stack.map((i) => `"${i.methods.join(',')} ${i.path}"`).join(', '), ']'))