import * as cors from 'cors';
import * as express from 'express';

var app = require('./config/app')
var corsOptions = {
  origin: (origin: string, callback: Function) => {
    if (app.whitelist.indexOf(origin) !== -1) {
      callback(null, true)
    } else {
      callback(new Error(`Not allowed by CORS. Origin: ${origin}`))
    }
  }
}

var router = express.Router();

//application
var appController = require('./controllers/appController');
router.route(['/', '/home']).get(appController.home)

//auth
var authController = require('./controllers/authController');
router.route('/auth/user').post(cors(corsOptions), authController.confirmToken);

module.exports = router;
