Code Monkey home page Code Monkey logo

ette-router's Introduction

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.

ette-router's People

Watchers

James Cloos avatar JSCON avatar

ette-router's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.