2017-07-04 16:43:07 +08:00
|
|
|
import koaRouter from 'koa-router'
|
|
|
|
import interfaceController from './controllers/interface.js'
|
|
|
|
import groupController from './controllers/group.js'
|
2017-07-05 17:59:53 +08:00
|
|
|
import userController from './controllers/user.js'
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-04 16:43:07 +08:00
|
|
|
const router = koaRouter();
|
2017-07-03 16:16:05 +08:00
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
const INTERFACE_CONFIG = {
|
|
|
|
interface: {
|
|
|
|
prefix: '/interface/',
|
|
|
|
controller: interfaceController
|
|
|
|
},
|
|
|
|
user: {
|
|
|
|
prefix: '/user/',
|
2017-07-06 18:25:53 +08:00
|
|
|
controller: userController
|
2017-07-05 16:17:58 +08:00
|
|
|
},
|
|
|
|
group: {
|
|
|
|
prefix: '/group/',
|
|
|
|
controller: groupController
|
|
|
|
}
|
2017-07-03 16:16:05 +08:00
|
|
|
};
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
//group
|
|
|
|
createAction('group', 'list', 'get', 'list')
|
|
|
|
createAction('group', 'add', 'post', 'add')
|
|
|
|
createAction('group', 'up', 'post', 'up')
|
|
|
|
createAction('group', 'del', 'post', 'del')
|
|
|
|
|
2017-07-06 18:25:53 +08:00
|
|
|
//user
|
|
|
|
createAction('user', 'login', 'post', 'login')
|
|
|
|
createAction('user', 'reg', 'post', 'reg')
|
|
|
|
createAction('user', 'list', 'get', 'list')
|
|
|
|
createAction('user', 'getUser', 'get', 'getUser')
|
|
|
|
createAction('user', 'update', 'post', 'update')
|
|
|
|
createAction('user', 'del', 'post', 'del')
|
|
|
|
|
2017-07-05 16:17:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {*} controller controller_name
|
|
|
|
* @param {*} path request_path
|
|
|
|
* @param {*} method request_method , post get put delete ...
|
|
|
|
* @param {*} action controller_action_name
|
|
|
|
*/
|
|
|
|
function createAction(controller, path, method, action){
|
|
|
|
router[method](INTERFACE_CONFIG[controller].prefix + path, async (ctx) => {
|
|
|
|
let inst = new INTERFACE_CONFIG[controller].controller(ctx);
|
|
|
|
await inst[action].call(inst, ctx);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = router
|
|
|
|
|