1.0.6 • Published 4 years ago

egg-yhsd-router v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

NPM version

egg router decorator -> 使用注解(decorator)定义API,简化路由配置。

!! 注意: 本插件只支持typescript版本的egg项目,js版本的暂未测试

安装

npm i egg-yhsd-router

使用方法

router入口中注入

// app/router.ts
import { Application } from 'egg';
import { RouterHandler } from 'egg-yhsd-router';

export default (app: Application) => {
  RouterHandler(app);
};

controller中使用注解(decorator)

// app/controller
import { Controller } from 'egg';
import { Get, Use, Prefix } from 'egg-yhsd-router';

@Prefix('/api')
export default class HomeController extends Controller {

  @Use([ 'middlewareName' ])  // 使用中间件。传入需要应用到该路由级别的中间件列表
  @Get('/') // 将该函数注册为path: /api ; method: GET 的api处理函数
  async index() {
    const { ctx } = this;
    ctx.body = await ctx.service.test.sayHi('egg');
  }
}

// 完成,访问 `http://host:port/api` 即可
1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago