Javascript 向node.js上的azure函数添加中间件函数

Javascript 向node.js上的azure函数添加中间件函数,javascript,node.js,azure,express,Javascript,Node.js,Azure,Express,我正在尝试在azure函数上复制您在express中可能拥有的中间件 例如: router.get('/protectedEndpoint', secured(), function (req, res) { 其中secured()函数是一个中间件,如果有效,它将发送next() azure的问题在于,它是按样式完成的 module.exports = function (context) { 我不确定如何在这种情况下使用next()运行中间件 下面是一个愚蠢的例子,说明该函数可能是什么样子

我正在尝试在azure函数上复制您在express中可能拥有的中间件

例如:

router.get('/protectedEndpoint', secured(), function (req, res) {
其中secured()函数是一个中间件,如果有效,它将发送next()

azure的问题在于,它是按样式完成的

module.exports = function (context) {
我不确定如何在这种情况下使用next()运行中间件

下面是一个愚蠢的例子,说明该函数可能是什么样子:

module.exports = function () {
  return function secured (req, res, next) {
    if (req.user) { return next(); }
    req.session.returnTo = req.originalUrl;
    res.redirect('/login');
  };
};

使用azure功能,您可以使用azure中间件引擎添加中间件,就像使用Express一样。通过此方法,您可以执行与使用Express相同的操作。 此引擎的链接如下所示


使用azure功能,您可以使用azure中间件引擎添加中间件,就像使用Express一样。通过此方法,您可以执行与使用Express相同的操作。 此引擎的链接如下所示


我认为它应该是
router.get('/protectedpoint',secured,function(req,res){…
像这样不
secured()
我认为它应该是
router.get('/protectedpoint',secured,function(req,res){…
像这样不
secured()
var MiddlewareHandler =  require('azure-middleware')

module.exports = new MiddlewareHandler()
.use((ctx) => {
   secured();//Your middleware function
   ctx.next();
})
.use(async (ctx) => {
   //Your controller or your main function script
      ctx.log.info('Im called third');
      ctx.done(null, { status: 200 });
})
.catch((error, ctx, msg) => {
    ctx.log.info(error); // ERROR!
    ctx.next();
 })
.listen();