As part of the Express server configuration, you load the ./comment_routes.js
file as shown in Listing 27.4. Listing 27.5 provides the routes necessary to get the page, photo, and comment data, as well as add additional comments to photos or pages.
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 photos.html
template is rendered on line 11. The routes in lines 13–17 all involve interaction with the MongoDB database and are handled in the controller route handlers described in the next section.
01 var express = require('express'),
02 module.exports = function(app) {
03 var photos = require('./controllers/photos_controller'),
04 var comments = require('./controllers/comments_controller'),
05 var pages = require('./controllers/pages_controller'),
06 app.use('/static', express.static( './static')).
07 use('/images', express.static( '../images')).
08 use('/lib', express.static( '../lib')
09 );
10 app.get('/', function(req, res){
11 res.render('photos'),
12 });
13 app.get('/photos', photos.getPhotos);
14 app.get('/photo', photos.getPhoto);
15 app.get('/page', pages.getPage);
16 app.get('/comments/get', comments.getComment);
17 app.post('/comments/add', comments.addComment);
18 }