1.2.7 • Published 3 years ago

koa-router-decorators-up v1.2.7

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

koa-router-decorators-up

本插件针对@rxts/koa-router-decorators进行更改拓展!

TOC

更改

  1. 解决在使用以后route挂载不上的问题(原因:没有引用controller文件注解不会触发
  2. Controller添加prefix

安装

# yarn
yarn add koa-router-decorators-up

# npm
npm i koa-router-decorators-up

使用方法

Controller的使用

import { Controller, get } from 'koa-router-decorators-up'
import * as Koa from 'koa'
@Controller('/test')
export default class startApi {
    // 括号中如果不传入参数  则自动拼接url 即:/test/getIndex
    @get()
    async getIndex(ctx: Koa.Context, next: Function) {
        ctx.body = {
            a : 66666
        }
    }
    @get('/getString')
    async getString(ctx: Koa.Context, next: Function) {
        ctx.body = 'koa2 string'
    }
}

路由注册

const app = new Koa()
import loadController from 'koa-router-decorators-up'
// 第二个参数为存放contorller的文件夹
loadController(router, resolve(__dirname, './controllers'))
app.use(router.routes())
app.use(router.allowedMethods())

License

MIT ©

1.2.0

3 years ago

1.1.0

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago