text: import bodyParser from 'body-parser';
  import cookieParser from 'cookie-parser';
  import Debug from 'debug';
  import express from 'express';
  import logger from 'morgan';
  import path from 'path';
  
  // import favicon from 'serve-favicon';
  
  import index from './routes/index';
  
  const app = express();
  const debug = Debug('api-test:app');
  const passport = require('passport');
  // const authRouter = require('./routes/auth/auth');
  
  const cors = require('cors');
  
  // uncomment after placing your favicon in /public
  // app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
  app.use(logger('dev'));
  app.use(bodyParser.json({ limit: '50mb' }));
  app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
  
  // OVER BLOCKING CROSS ORIGIN REQUEST
  app.use((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, POST, PUT, DELETE, OPTIONS');
    next();
  });
  
  app.use(cors());
  
  app.use(cookieParser());
  
  app.use(express.static(path.join(__dirname, 'public')));
  
  app.use('/', index);
  
  app.get('*', (req, res) => {
    res.sendFile(path.join(__dirname, 'public', 'index.html'));
  });
  
  
  app.get('/profile', passport.authenticate('jwt', { session: false }), (req, res) => {
    res.send(req.user);
  });
  
  // catch 404 and forward to error handler
  app.use((req, res, next) => {
    const err = new Error('Not Found');
    err.status = 404;
    next(err);
  });
  
  // error handler
  /* eslint no-unused-vars: 0 */
  app.use((err, req, res, next) => {
    // set locals, only providing error in development
    res.locals.message = err.message;
    res.locals.error = req.app.get('env') === 'development' ? err : {};
    // render the error page
    res.status(err.status || 500);
    res.json(err);
  });
  
  // Handle uncaughtException
  process.on('uncaughtException', (err) => {
    debug('Caught exception: %j', err);
    process.exit(1);
  });
  
  export default app;
  