text: import express from 'express';
  import path from 'path';
  import logger from 'morgan';
  import bodyParser from 'body-parser';
  import routes from './routes';
  
  const app = express();
  app.disable('x-powered-by');
  
  // View engine setup
  app.set('views', path.join(__dirname, '../views'));
  app.set('view engine', 'pug');
  
  app.use(logger('dev', {
    skip: () => app.get('env') === 'test'
  }));
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(express.static(path.join(__dirname, '../public')));
  
  // Enable CORS
  // https://enable-cors.org/server_expressjs.html
  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();
  });
  
  // Routes
  app.use('/', routes);
  
  // 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
  app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
    res
      .status(err.status || err.statusCode || 500)
      .render('error', {
        message: err.message
      });
  });
  
  export default app;
  