Skip to content

@koa/router or koa-router extension controller 简单易用的路由扩展控制器

Notifications You must be signed in to change notification settings

jasonsoft-net/jasonsoft-koa-controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Icon 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';
};

License

MIT

About

@koa/router or koa-router extension controller 简单易用的路由扩展控制器

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published