huhu2356 / toy-koa-router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

toy koa router

npm

Installation

$ npm install toy-koa-router

Example

const Koa = require('koa');
const KoaRouter = require('toy-koa-router');

const app = new Koa();
const router = new KoaRouter();

router.get('/abc/:id',
    async (ctx, next) => {
        console.log(1);
        await next();
        console.log(3);
    },
    async (ctx, next) => {
        console.log(2);
        await next();
        console.log(4);
    }
);

app.use(router.routes());

app.use((ctx, next) => {
    console.log(5);
    ctx.body = 'nice';
});

app.listen(3000);

License

MIT

About

License:MIT License


Languages

Language:JavaScript 100.0%