I know that I can chain middleware functions after passing in the route like

```
const express = require('express');
const router = express.Router();
router.post('/', middlewareFunction1, middlewareFunction2, controllerFunction);
module.exports = router;

```

I would like to know if it's possible to call only one function (called gateway)

```
router.post('/', gatewayFunction1);

```

and this function is able to chain all those methods

```
const controller = require('../controllers/controller');

function gatewayFunction1(request, response, next) {
  // validate route
  // do other middleware stuff
  // call controller.function1
}

module.exports = {
  gatewayFunction1,
};

```

Why would I do that? I was thinking about separating the middleware logic from the routes. This gateway should just get executed after routing and before calling the router.

I tried to return an array of functions (example code)

```
function gatewayFunction1(request, response, next) {
  return [(request, response, next) => {
    console.log('called middleware 1');
    next();
  }, (request, response, next) => {
    console.log('called middleware 2');
    next();
  }, (request, response, next) => {
    response.status(200).json({
      message: 'that worked',
    });
  }];
}

```

but when I call this api route I get no response

> 
> Could not get any response
> 
> 
> 

so it keeps loading forever. Is there a way to chain these middleware functions within another function?