/**
 * Main application routes
 */

'use strict';

var errors = require('./components/errors');


module.exports = function(app) {

  // Enable CORS
  app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE');
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
    next();
  });

  // Api routes
  app.use('/api/feedbacks', require('./api/feedback'));
  app.use('/api/users', require('./api/user'));
  app.use('/api/subscribers', require('./api/subscriber'));

  // Custom routes
  app.use('/images', require('./upload'));
  app.use('/auth', require('./auth'));

  // All other routes should redirect to the index.html
  app.route('/*')
    .get(errors[404]);
};