Implementing Routes to Support the Views

As part of the Express server configuration, you load the ./rich_ui_routes.js file shown in Listing 29.2. Listing 29.3 provides the routes necessary to load the tabbed view, access the words database, access the backend weather service, and get the necessary static files.

Lines 6–9 implement the static routes to support getting the AngularJS, CSS, JavaScript, images, and AngularJS partial templates used in this example. The images and AngularJS lib folders are located in a sibling directory to the project. The other static files are in the ./static folder inside the project.

Notice that when the user accesses the root location for the site (/), the rich_ui.html template is rendered on line 10. The /weather route gets data through the getWeather() handler in weather_controller.js. The /words route provides interaction with the MongoDB database through the words_controller.js controller.

Listing 29.3 rich_ui_routes.js: Implementing the routes for web application requests from the client


01 var express = require('express'),
02 module.exports = function(app) {
03   var weather = require('./controllers/weather_controller'),
04   var words = require('./controllers/words_controller'),
05   app.use('/static', express.static( './static')).
06       use('/images', express.static( '../images')).
07       use('/lib', express.static( '../lib')
08   );
09   app.get('/', function(req, res){
10     res.render('rich_ui'),
11   });
12   app.get('/weather', weather.getWeather);
13   app.get('/words', words.getWords);
14 };


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.179.239