one.io
1️⃣ A feature-rich routing middleware for koa2.
Prerequisites
- Node.js 7+
Install
npm install one.io --save
or
yarn add one.io
Usage
router
Initialize your router in 'app.ts'
// app.ts;; ;;router.routesApp; App.listen4000;
api route
Build your routes under the directories.
;
page route
Render data for pages.
;
permission
If permission support is needed, you should import class Permission and implement it.
; // then build your permissions.;
Options
router
- apiPath: A directory for api routes. Optional, default is './route/api'.
- pagePath: A directory for page routes. Optional, default is './route/page'.
- cookies: Set the keys for user name and token. Optional, default is '{ user: 'user', token: 'token' }'
api & page
- path: Path for the route. Optional, automatically transform from method name.
For example, a method named 'userRegister' means the route path is '/user/register'
- permission: Set a permission for a route. Optional, default value is 'undefined'.
Features
- Parse http request body.
- Verify Permission and token.
- Validate request parameters.
- Written in TypeScript with complete define types.
License
MIT License.