我正在为 lambda 函数编写中间件。
主要的 Lambdaexports
如下所示:
const Middleware = require('...');
async function myF(event, context) {
console.log(event);
}
module.exports = Middleware(myF);
中间件看起来像这样:
module.exports = next => async function (event, context, callback) {
console.log(event)
return await next(event, context, callback)
}
一切正常!
现在我想通过添加函数和状态来改进中间件。我试图从简单的中间件函数中创建一个“类”:
async function Middleware(event, context, callback) {
console.log(event)
return await next(event, context, callback)
}
module.exports = next => Middleware
问题:
next
没有定义。如何使其在函数中可访问?- 这不是一个真正的班级
免责声明:我对 NodeJs/ECSM6 中的这些概念并不十分熟悉。