我是个打字新手。现在我想获取接口响应信息(包括Elapsed time,response status,api route).I刚刚在githubresponse-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()
}
}发布于 2020-07-30 13:36:09
您传递的不是responseTime的next,而是一个字符串或日期/数字,我看到有'' time '‘作为第三个,我不确定“这里的一些代码”做什么,但似乎正在尝试调用next的时间
https://stackoverflow.com/questions/63166632
复制相似问题