1.让中间件只在某个路由中使用

  1. // 增加配置中间件
  2. config.middleware = ['cors','compress','auth'];
  3. /* 使用match只在news中使用 */
  4. config.auth = {
  5. match:'/news',
  6. title:"this is middleware"
  7. }

match也可以是一个函数

  1. config.auth = {
  2. match(ctx){
  3. if(ctx.url == "/news" || ctx.url =="/shops"){
  4. return true
  5. }else{
  6. return false
  7. }
  8. },
  9. title:"this is middleware"
  10. }