gpt4 book ai didi

node.js - ExpressJS中定义的get、post方法在哪里?

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:33 25 4
gpt4 key购买 nike

我找不到 getpost 方法的代码。我没有在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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com