1.2.0 • Published 4 years ago

jasonsoft-koa-controller v1.2.0

Weekly downloads
52
License
MIT
Repository
github
Last release
4 years ago

jasonsoft-koa-controller

@koa/router or koa-router extension controller

NPM version NPM Downloads License

NPM NPM

Installation

$ npm install jasonsoft-koa-controller --save-prod

Example
Basic usage:

import Koa from 'koa';
import Router from '@koa/router';
import controller from 'jasonsoft-koa-controller';

const app = new Koa();
const router = new Router();

// 注入控制器 默认路由控制器路径 'src/controllers'
controller(router);

// 注入控制器 自定义路径
// controller(router, 'src/controllers');

app.use(router.routes()).use(router.allowedMethods());

app.listen(3000);

Create a test controller:

// 新建控制器 src/controllers/test.js

/** 
 * 请求方式: get post put del all 
 * 这里如果不指定请求方式,默认为 all 
 */
export const method = 'all'; 

/**
 * 测试API
 * http://localhost:3000/test
 * Added by Jason.Song on 2021/01/11 19:48:39
 */
export default (ctx, next) => {
  ctx.body = '测试API';
};

完整示例 Example

License

MIT

1.2.0

4 years ago

1.1.9

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

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.3

4 years ago

1.0.0

4 years ago