Reputation: 1774
I have an application on Express 4.x integrated with the Twilio API and dependent on the Input from the users' phone, I will respond with different XML files that may or may not be created dynamically.
Where am I supposed to put this theoretical route conditional? i.e.
exports.handle = function(req, res) {
if(req.body.digits == 1){
//pass to first option handler
}
if (req.body.digits == 2) {
//create xml file dynamically
//for second option
}
else {
//handle else
}
};
It seems a bit heavy to be putting into the routes file. In such MVC structure is it typical to put this conditional into a controller? Or stuff the routes? Or is there another option that I'm unaware of?
I'd much rather just have this code pass all requests to a single handler. i.e.
exports.handle = function(req, res) {
if (req.body.digits)
//send to handler
};
Where does this go? What is it called?
Upvotes: 1
Views: 45
Reputation: 121
In this scenario, your router is your "single handler". You are channeling all input through the routing mechanism and letting it decide who the appropriate handler (or controller) is. This is commonly referred to as "front controller". It makes sense to put the logic handler in the file you are referencing if you architect your software with this in mind.
Upvotes: 1