I have many routes like:
//routes
app.get("page1/:action", function(req, res) {
...
}
app.get("page2/:action", function(req, res) {
...
}
where page1 and page2 are two controllers and the :action is the “method” I need to call. The pages should be:
- /page1/delete
- /page1/modify
- /page1/add
I try to organize my code to simplify the job following a MVC system.
Could someone give me an advice regarding, how can I call the method of a controller by reading the parameter I use as :action I need to check if the method exists if not (if someone write /page1/blablabla) I return a 404 http error.
Thank you!
Here’s an example on how to achieve this. You can read more on this on the Expressjs guide: http://expressjs.com/guide/error-handling.html