donal
2018-04-04 2bb44eb0c09150f47137955f6a0d2ae55b714fa4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/**
 * Main application routes
 */
 
'use strict';
 
const errors = require('./components/errors');
const path = require('path');
 
module.exports = function(app) {
  
  app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    next();
  });
  // Insert routes below
  app.use('/api/todos', require('./api/todo'));
 
  // All undefined asset or api routes should return a 404
  app.route('/:url(api|components|app|bower_components|assets)/*')
   .get(errors[404]);
 
  // All other routes should redirect to the index.html
  app.route('/*')
    .get(function(req, res) {
      return res.status(200).json({OK: true, timestamp: Date.now()});
      // res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
    });
};