Created
October 25, 2016 07:36
-
-
Save nulltask/e66748662d02b716a29c1d80a7232fa5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Koa = require('koa'); | |
const Router = require('koa-router'); | |
const app = new Koa(); | |
const router = new Router(); | |
app.use(async (ctx, next) => { | |
const { request, response } = ctx; | |
const now = Date.now(); | |
await next(); | |
console.log(`${request.method} ${request.url} ${response.status} ${response.length} - ${Date.now() - now} ms`); | |
}); | |
router.get('/', async (ctx, next) => { | |
ctx.body = { hello: 'world' }; | |
}); | |
app.use(router.routes()).listen(process.env.PORT); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('async-to-gen/register'); | |
require('./app'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"async-to-gen": "^1.1.4", | |
"koa": "^2.0.0", | |
"koa-router": "^7.0.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment