Routers and controllers
So far, you have your server.js
file and a configure
module that is used to wire up all of the necessary middleware for the application. The next step is to implement a proper router and controller.
The router is going to be a map of each of the available URL paths for the app. Every route on the server will correspond to a function in a controller. Here is what our routes table will look like for the particular application we are writing:
GET /(index) - home.index (render the homepage of the site) GET /images/image_id - image.index (render the page for a specific image) POST /images - image.create (when a user submits and uploads a new image) POST /images/image_id/like - image.like (when a user clicks the Like button) POST /images/image_id/comment - image.comment (when a user posts a comment)
You can see that we are handling two different GET
requests and three different POST
requests. In addition, we have two main controllers: home
and image
. Controllers are really...