Skip to content

Instantly share code, notes, and snippets.

@nulltask
Created October 25, 2016 07:36
Show Gist options
  • Select an option

  • Save nulltask/e66748662d02b716a29c1d80a7232fa5 to your computer and use it in GitHub Desktop.

Select an option

Save nulltask/e66748662d02b716a29c1d80a7232fa5 to your computer and use it in GitHub Desktop.

Revisions

  1. nulltask created this gist Oct 25, 2016.
    19 changes: 19 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@

    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);
    3 changes: 3 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@

    require('async-to-gen/register');
    require('./app');
    7 changes: 7 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    {
    "dependencies": {
    "async-to-gen": "^1.1.4",
    "koa": "^2.0.0",
    "koa-router": "^7.0.1"
    }
    }