var express = require('express');
var logger = require('morgan');
var bodyParser = require('body-parser');

var auth = require('./routes/auth');
var geocache = require('./routes/geocache');
var profiles = require('./routes/profiles');
var users = require('./routes/users');

var app = express();

app.use(logger('dev'));
app.use(bodyParser.json({ limit: '5mb' }));
app.use(bodyParser.urlencoded({ extended: false }));
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");
  next();
});


app.use('/auth', auth);
app.use('/geocache', geocache);
app.use('/profiles', profiles);
app.use('/users', users);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
  var err = new Error('Not Found', { args: arguments });
  err.status = 404;
  next(err);
});

module.exports = app;
