add logger for development
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
a324047cd7
commit
9d32799486
|
@ -8,6 +8,7 @@
|
|||
"async-redis": "^1.1.4",
|
||||
"koa": "^2.5.3",
|
||||
"koa-json": "^2.0.2",
|
||||
"koa-logger": "^3.2.0",
|
||||
"koa-router": "^7.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import Koa from 'koa'
|
||||
import Router from 'koa-router'
|
||||
import JSON from 'koa-json'
|
||||
import Logger from 'koa-logger'
|
||||
|
||||
import Counter from './counter'
|
||||
import Redis from 'async-redis'
|
||||
|
@ -15,6 +16,10 @@ const router = new Router()
|
|||
const redis = Redis.createClient(REDIS_PORT, REDIS_HOST)
|
||||
const counter = new Counter(redis)
|
||||
|
||||
app.on('error', (err, ctx) => {
|
||||
console.error('server error', err, ctx)
|
||||
});
|
||||
|
||||
router.put('/clicks/:id', async ctx => {
|
||||
counter.incr(ctx.params.id)
|
||||
ctx.body = { [ctx.params.id]: await counter.state(ctx.params.id) }
|
||||
|
@ -28,7 +33,8 @@ router.get('/clicks/:id', async ctx => {
|
|||
ctx.body = { [ctx.params.id]: await counter.state(ctx.params.id) }
|
||||
});
|
||||
|
||||
app.use(JSON({pretty: true}))
|
||||
app.use(Logger())
|
||||
.use(JSON({pretty: true}))
|
||||
.use(router.routes())
|
||||
.use(router.allowedMethods())
|
||||
|
||||
|
|
Loading…
Reference in New Issue