wee-router

0.0.1 • Public • Published

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 at ctx.params or ctx.request.params

Options

Default options (As convention)

{
    cwd: process.cwd(),
    routes: 'config/routes.json'
}
  • cwd current working directory
  • routes routes table defination file, relative to cwd

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i wee-router

Weekly Downloads

1

Version

0.0.1

License

MIT

Last publish

Collaborators

  • capasky