move logging setup to server.js
This commit is contained in:
parent
16fbf0e34b
commit
ff2907cadd
10
src/app.js
10
src/app.js
|
@ -1,12 +1,15 @@
|
|||
import Koa from 'koa'
|
||||
import Router from 'koa-router'
|
||||
import JSON from 'koa-json'
|
||||
import Logger from 'koa-logger'
|
||||
|
||||
const App = (counter) => {
|
||||
const app = new Koa()
|
||||
const router = new Router()
|
||||
|
||||
app.use(router.routes())
|
||||
.use(router.allowedMethods())
|
||||
.use(JSON({pretty: true}))
|
||||
|
||||
app.on('error', (err, ctx) => {
|
||||
console.error('server error', err, ctx)
|
||||
});
|
||||
|
@ -25,11 +28,6 @@ const App = (counter) => {
|
|||
ctx.body = { [ctx.params.id]: await counter.state(ctx.params.id) }
|
||||
});
|
||||
|
||||
app.use(Logger())
|
||||
.use(JSON({pretty: true}))
|
||||
.use(router.routes())
|
||||
.use(router.allowedMethods())
|
||||
|
||||
return app
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import Redis from 'async-redis'
|
||||
import Logger from 'koa-logger'
|
||||
|
||||
import App from './app'
|
||||
import Counter from './counter'
|
||||
|
@ -11,6 +12,9 @@ const LISTEN_PORT = process.env.LISTEN_PORT || 3000
|
|||
const redis = Redis.createClient(REDIS_PORT, REDIS_HOST)
|
||||
const counter = new Counter(redis)
|
||||
const app = App(counter)
|
||||
|
||||
app.use(Logger())
|
||||
|
||||
app.listen(LISTEN_PORT)
|
||||
|
||||
console.log(`Redis connection: ${REDIS_HOST}:${REDIS_PORT}`)
|
||||
|
|
Loading…
Reference in New Issue