U
U
user_of_toster2020-12-23 17:00:48
Express.js
user_of_toster, 2020-12-23 17:00:48

What functions is the controller responsible for in MVC on express?

What is the controller in express responsible for with its middleware chain? I have several options in my head:

1) Only for routing. Accepts urls and redirects all responsibility to another module.

//controller.js
router.get('/', business.indexPageMiddlewareList)


2) Only for the processing sequence. Router.js should be responsible for routing, in the controller there is only a sequence of middleware and business logic at the end
//controller.js
const indexPage = [loggermiddleware, ...., business.getpage]


3) For routing and processing sequence. PS: the controller starts doing the two functions above.
//controller.js
router.get('/', logger_middleware, auth_middleware, business.indexPage)


4) The controller is only responsible for the business logic
//controller.js
const get_data = (req, res, next) => {}....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2020-12-23
@user_of_toster

without binding to express: controller is a simple dispatcher between request and response. it should be as blunt as possible.
middleware can work generally before the controller.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question