首页 > 其他 > 详细

express源码剖析--Router模块

时间:2017-01-09 20:30:18      阅读:150      评论:0      收藏:0      [点我收藏+]

1.加载模块执行代码:

methods.forEach(function(method){
  //method是http协议的各种请求方法,如:get,put,headee,post
  Route.prototype[method] = function(){
      ....为method的各种方法构造一个Layer,并且放入stack数组中
  };
});
//其实router.all()的功能和methods的功能差不多。

2.构造函数

function Route(path) {
  //三个成员, 路由的路径,方法对象。和储存对应的请求处理函数
  this.path = path;
  this.stack = [];

  debug(‘new %s‘, path);

  // route handlers for various http methods
  this.methods = {};
}

3.原型对象上方法

Route.prototype ={
  /*返回boolean类型,判断router是否支持给定的method方法*/
   _handles_method:_handles_method(method),
  /*返回一个rounter所支持的HTTP请求的数组*/
    _options:_options(),
  //把http请求通过router对象定义好的method方法处理,
  //也就是对req.route = this,定义next函数,
   dispatch:function dispatch(req, res, done)    
}

 

 

 

express源码剖析--Router模块

原文:http://www.cnblogs.com/liuyinlei/p/6266185.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!