我找不到 get
或 post
方法的代码。我没有在expressjs lib文件夹中找到它们,因此它们可能存在于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
参数传递给上面回调函数的位置,因为它必须由 ExpressJS 框架在后台完成。
最佳答案
Express 使用 methods将 http 动词动态附加到路由器的模块:
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;
};
});
关于node.js - ExpressJS中定义的get、post方法在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33891772/