As part of the Express server configuration, you load the ./cart_routes.js
file shown in Listing 28.7. Listing 28.8 provides the routes necessary to get the customer, product, and order objects. It also provides routes to add orders to the database and update the customer shipping, billing, and cart information.
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 shopping.html
template is rendered on line 11. The remaining routes on lines 13–19 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 customers = require('./controllers/customers_controller'),
04 var products = require('./controllers/products_controller'),
05 var orders = require('./controllers/orders_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('shopping'),
12 });
13 app.get('/products/get', products.getProducts);
14 app.get('/orders/get', orders.getOrders);
15 app.post('/orders/add', orders.addOrder);
16 app.get('/customers/get', customers.getCustomer);
17 app.post('/customers/update/shipping', customers.updateShipping);
18 app.post('/customers/update/billing', customers.updateBilling);
19 app.post('/customers/update/cart', customers.updateCart);
20 }