由于某种原因,restify 的正文解析器无法正常工作
restify's body parser is not working for some reason
我不明白为什么会这样:
instance.use(restify.bodyParser());
但这不起作用:
instance.use((req, res, next) => {
restify.bodyParser();
next();
});
UPD: 我试过 restify.bodyParser()(req, res, next)
。事实上,由于某种原因它不起作用。
restify.bodyParser()
导出函数数组:[read, parseBody]。所以使用 restify.bodyParser()(...)
会抛出错误 ... is not a function
.
我还在努力弄明白为什么会这样。
use
期望 argument of the form function (req, res, next)
or an array of functions of this form。 restify.bodyParser()
是这种形式的函数数组。因此,您需要将 req
、res
、next
传递给数组中的每个函数。根据您想要执行的操作,您可能需要 return 中间件数组或按顺序调用中间件。
如果您来这里寻找相同错误消息的答案'restify.bodyParser is not a function'...
自 restify 版本 5.* 起,restify 的 bodyParser 函数应为:
restify.plugins.bodyParser()
在当前版本的Restify中,使用插件restify.plugins.bodyParser()
。
我不明白为什么会这样:
instance.use(restify.bodyParser());
但这不起作用:
instance.use((req, res, next) => {
restify.bodyParser();
next();
});
UPD: 我试过 restify.bodyParser()(req, res, next)
。事实上,由于某种原因它不起作用。
restify.bodyParser()
导出函数数组:[read, parseBody]。所以使用 restify.bodyParser()(...)
会抛出错误 ... is not a function
.
我还在努力弄明白为什么会这样。
use
期望 argument of the form function (req, res, next)
or an array of functions of this form。 restify.bodyParser()
是这种形式的函数数组。因此,您需要将 req
、res
、next
传递给数组中的每个函数。根据您想要执行的操作,您可能需要 return 中间件数组或按顺序调用中间件。
如果您来这里寻找相同错误消息的答案'restify.bodyParser is not a function'...
自 restify 版本 5.* 起,restify 的 bodyParser 函数应为:
restify.plugins.bodyParser()
在当前版本的Restify中,使用插件restify.plugins.bodyParser()
。