- Build an Express controller.
- Define 3 actions for the controller.
- Render the appropriate views in each action.
- Mount the controller in the app.
- Draw routes for the app to the controller actions.
Your goals is to build an express application using the C (controllers) in the M-V-C paradigm of application development. Your site will respond to 3 URLs, each mapping to a discrete controller action defined as a function in the SiteController
class.
GET '/'
should map toSiteController.Index
and rendersite/index
creating a Home Page.GET '/about'
should map toSiteController.About
and rendersite/about
creating an About Page.GET '/contact'
should map toSiteController.Contact
and render'site/contact
creating a Contact Page.
We've given you the views for this application in views/site
, so you don't need to worry about them.
Build the controller in controllers/SiteController.js
by defining an object for SiteController
and attaching functions to handle the express routes directly onto that object.
Remember, functions that are valid express handlers need to accept at least two arguments, generally called req
and resp
. These functions become the controller's actions. Each function should use the resp
to render the apporpriate view.
Finally, make sure to export the controller so you can mount the controller in app.js
using require
. Then create the routing table in app.js
using the express app
constant and passing each URL to the appropriate controller action.
You can run the tests with learn
. The tests specify the full flow for each URL sequentially.
You can run the server with npm start
and preview it in your browser.