ts-decorate
v1.1.6
Published
``` npm i ts-decorate ```
Downloads
57
Readme
Install
npm i ts-decorate
How to use ?
import Koa from 'koa'
import TsRouter from 'ts-decorate'
const app = new Koa()
app.use({
cwd: path.resolve(__dirname, 'controllers'),
reg: './*.js',
prefix: '/view'
})
cwd: 路由类所在目录
reg: glob模块查找文件的匹配模式
prefix: 所有路由的前缀, 可以省略API
- Class decorator
import { Base } from 'ts-decorate'
@Base('/xx')
export default class xx{}
设置当前类下的所有路由前缀; 可以省略- Method decorator
import { GET, POST } from 'ts-decorate'
export default class xx{
@GET('/xx')
async xxxx(){
return {code: 200, data:xx, msg: xx}
}
@POST('/xx')
async xxxx(){}
}- Params decorator
// 字符串形式
@GET(xxx)
getInfo(@params('name title') name: string, title: string, ctx, next){}
// 多修饰形式
@GET(xxx)
getInfo(
@params('name') name: string,
@params('title) title: string,
ctx, next
){}
ctx, next 这两个参数选传