RT, 使用了 sails 之后,再回去 express / koa 之后路由又是麻烦事, impress-router 将 sails 的 routes config 移植到 koa, 直接指定顶级文件夹(即 sails 中的 api 文件夹)
链接
https://github.com/magicdawn/impress-router-table
简短说明
在 api 这个顶级文件夹下, 有 controllers / policies / policy.js / routes.js 即可使用声明式的路由定义, 这里有完整示例 https://github.com/magicdawn/impress-router-table/blob/master/test/demo/app.js
下边是 README.md ----------------------- 我是分割线 ------------------------------
impress-router-table
Sails.js like routing for koa.js
Install
$ npm i impress-router-table --save
API
const routing = require('impress-router-table');
routing(rootdir)
returns a koa middleware
const app = new (require('koa'))
app.use(routing(__dirname + '/api'))
app.listen(9000)
Folder structure in rootdir
for example in previous example, __dirname + '/api'
,
take a look at test/demo/api/
test/demo/api
├── controllers
│ ├── PolicyTestController.js
│ └── RouteTestController.js
├── policies
│ ├── auth.js
│ └── bar.js
├── policy.js # policy config
└── routes.js # routes config
2 directories, 6 files
Changelog
License
the MIT License http://magicdawn.mit-license.org