1.0.3 • Published 2 years ago

ette-router v1.0.3

Weekly downloads
23
License
-
Repository
github
Last release
2 years ago

ette-router

Build Status Coverage StatusMIT Licence npm version

Router middleware for ette.

  • written in Typescript
  • used with koa style
  • fully tested

Installation

Node.js / Browserify

npm install ette-router --save
var Router = require('ette-router');

Global object

Include the pre-built script.

<script src="./dist/index.umd.min.js"></script>

Build & test

npm run build
npm test

Usage

param

example: https://repl.it/@boycgit/ette-router-param

test your router rule: http://forbeslindesay.github.io/express-route-tester/

document

npm run doc

then open the generated out/index.html file in your browser.

注:你写路由匹配规则时的 / 是很重要的,但你在用 request 方法中的 path 里的 / 则是无关紧要的;

你需要区分 路由规则中间件 这两个概念。

直接使用 use 的是 中间件

router.use('/', function(ctx, next) {
    // your code...
    return next();
});

使用 HTTP.verb() 的时候,定义的则是 路由规则

router.get('/', function(ctx, next) {
    // your code...
    return next();
});

路由规则 本质上也是中间件

在代码层面,这部分差别是在 Router#match() 方法返回的 MatchedRouter 类型的 route 属性是否是 true 来区分的,如果为 true 表示路由规则,如果是 false 表示定义是中间件

注意:只有当匹配路由规则的时候才会运行相关的中间件,匹配中间件上的 path 并不会运行中间件!!

License

MIT.

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

3 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.5

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago