Guest User

Untitled

a guest
Jan 14th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Koa = require('koa')
  2. const Router = require('@koa/router')
  3.  
  4. class MyRouter extends Router {
  5.     routes() {
  6.         console.log(this.stack)
  7.         return super.routes()
  8.     }
  9. }
  10.  
  11. const router = new MyRouter()
  12. router.get('/', async (ctx, next) => {
  13.     ctx.body = 'default middleware'
  14. })
  15. router.get('/', async (ctx, next) => {
  16.     ctx.body = 'my middleware'
  17. })
  18.  
  19. const app = new Koa()
  20. app.use(router.routes())
  21. app.listen(3000)
Advertisement
Add Comment
Please, Sign In to add comment