wee-router
v0.0.1
Published
A router middleware for wee.
Downloads
2
Readme
wee-router
A router middleware for easywee. Convention over Configuration
Installation
npm install wee-router --save
Usage
const router = require('wee-router');
const app = require('koa')();
app.use(router({
routes: './routes.js' // routes table defination file
}));
app.listen(5000);
Then define route in the routes.js
file
module.exports = [
"get /login => accounts#login",
"get /logout => accounts#logout",
//rest api
"get /posts", //get all posts
"get /posts/:id", //get a post using id :id, such as "/posts/211" will get a parameter id=211
"post /posts", //create a post
];
We recommend using .js
file to define routing information, because you can use the comments to describe the route in .js
file . Also you can define the routing table using .json
file.
Route data will be stored at
ctx.route
in every request, and route params will be stored atctx.params
orctx.request.params
Options
Default options (As convention
)
{
cwd: process.cwd(),
routes: 'config/routes.json'
}
cwd
current working directoryroutes
routes table defination file, relative to cwd