chain middleware functions in custom function chain middleware functions in custom function express express

chain middleware functions in custom function


Your gatewayFunction1 does nothing except returns an array.Just use router.

const express = require('express');const gatewayFunction1 = express.Router();gatewayFunction1.use(middlewareFunction1, middlewareFunction2, controllerFunction);module.exports = gatewayFunction1;

Then

const gatewayFunction1 = require('...');  // where you define gatewayFunction1router.post('/', gatewayFunction1);


Middleware should be a function and you are returning an array.If next function is not called it will get stuck. I don't like the whole idea combining them but I think the best way is to import all your middleware functions in one function and call them individually then use that function as your combined middleware.