node.js - nodejs.TypeError:下一个不是函数
问题描述
我是打字稿的新手。现在我想获取api响应信息(包括Elapsed time
,,,response status
)api route
。我刚刚在github response-time中找到了一个中间件。我只是在启动时简单地使用了这个中间件。
export default (app: Application) => {
//some code here
var responseTime = require('response-time')
app.use(responseTime(function (req, res, time) {
//some code here
}))
};
当我npm run dev
,我得到
2020-07-30 11:28:21,929 ERROR 85820 [-/127.0.0.1/-/1ms GET /favicon.ico] nodejs.TypeError: next is not a function
at responseTime (/Users/lithium/develop/one-authentication-center/node_modules/response-time/index.js:61:12)
at dispatch (/Users/lithium/develop/one-authentication-center/node_modules/koa/node_modules/koa-compose/index.js:42:32)
at /Users/lithium/develop/one-authentication-center/node_modules/koa/node_modules/koa-compose/index.js:34:12
at MidwayApplication.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/koa/lib/application.js:166:12)
at MidwayApplication.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/egg/lib/application.js:211:18)
at Server.handleRequest (/Users/lithium/develop/one-authentication-center/node_modules/koa/lib/application.js:148:19)
at Server.emit (events.js:314:20)
at parserOnIncoming (_http_server.js:777:12)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
pid: 85820
我打开了 response-time/index.js,代码引发的错误是
var fn = typeof opts !== 'function'
? createSetHeader(opts)
: opts
return function responseTime (req, res, next) {
var startAt = process.hrtime()
onHeaders(res, function onHeaders () {
var diff = process.hrtime(startAt)
var time = diff[0] * 1e3 + diff[1] * 1e-6
fn(req, res, time)
})
next()
}
}
解决方案
你没有传递下一个 responseTime 而是一个字符串或日期/数字,我看到“时间”作为第三个不确定“这里的一些代码”做了什么,但似乎正试图按时调用下一个
推荐阅读
- c# - 在开发人员命令提示符下运行单元测试
- java - 尝试修复 html 表的 colspans 和 rowspans Java
- io - 如何在 Perl 6 中附加到文件?
- javascript - 如何使用扩展语法返回对象并覆盖引用数组的属性
- r - 如何获取值高于阈值 + 列索引约束的行数?
- visual-studio-2013 - SSIS 获取数据流中所有 OLE DB 目标的列表
- c# - C# 中 InitializeComponent() 方法中“this.lblDelete.Click += new System.EventHandler(this.lblDelete_Click);”的目的是什么?
- python - 在 opencv 3.x 中设置 FPS
- graphviz - 当 dir=back 时,Graphviz 箭头不起作用
- angularjs - AngularJS HTML 属性中的 Typescript 枚举