在哪里得到,在ExpressJS中定义的发布方法?
我无法findget
或post
方法的代码。 我没有在expressjs lib文件夹中find它们,所以可能它们存在于Router
需要的js文件之一中。
var express = require('express'); var router = express.Router(); var Blah = require('../modules/Blah'); router.post('/', function(req, res, next) { Blah.foo(req, res); });
我需要它来找出next
parameter passing到上面的callback函数的地方,因为它必须由ExpressJS框架来完成。
Express使用方法模块将http动词dynamic附加到路由器上:
lib / router / index.js:
// create Router#VERB functions methods.concat('all').forEach(function(method){ proto[method] = function(path){ var route = this.route(path) route[method].apply(route, slice.call(arguments, 1)); return this; }; });
有关更多详细信息,请参阅KeatsPeeks的答案。 以下是一些可能有用的源代码的特定部分的链接:
-
get
和post
方法在这里的methods
模块中定义: https : //github.com/jshttp/methods/blob/master/index.js#L14-L15 -
在
lib/applciation.js
对它们的调用被委托给router.METHOD
: https : //github.com/strongloop/express/blob/master/lib/application.js#L471-L484 -
剩下的是在
lib/router/index.js
: https : //github.com/strongloop/express/blob/master/lib/router/index.js#L506-L513 -
在
lib/router/route.js
– 在https://github.com/strongloop/express/blob/master/lib/router/route.js中search“methods
”