'use strict';

const bodyParser = require ('body-parser');
const passport   = require ('passport');
const express    = require ('express');
const winston    = require ('winston');
const helmet     = require ('helmet');
const cors       = require('cors');

const organizationRoutes  = require ('./api/v1/organizations/organizationRoutes');
const signUpRoutes        = require ('./api/v1/signUp/signUpRoutes');
const boardRoutes         = require ('./api/v1/board/boardRoutes');
const loginRoutes         = require ('./api/v1/login/loginRoutes');
const userRoutes          = require ('./api/v1/users/userRoutes');

const config  = require ('./config/config');
const log     = require ('./libs/winston')(module);
const dbTest  = require ('./config/dbTest');
const db      = require ('./config/db');

const passportMiddleweare = require ('./utils/passportMiddleweare');

const port = 80;

const app = express ();

app.use(passport.initialize());
app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.user(cors());

app.disable('x-powered-by');

app.use('/api/v1/login', passportMiddleweare.isAuthenticatedWithBasic, loginRoutes);
app.use('/api/v1/signup', signUpRoutes);
app.use('/api/v1/users', passportMiddleweare.isAuthenticatedWithToken, userRoutes);
app.use('/api/v1/organizations', passportMiddleweare.isAuthenticatedWithToken, organizationRoutes);
app.use('/api/v1/boards', passportMiddleweare.isAuthenticatedWithToken, boardRoutes);

app.get('*', (req, res) => {
	res.status(404).json({
		status: 404,
		message: 'The requested URL ' + req.originalUrl + ' was not found on the server.'
	});
});

let server = app.listen(port, (err) => {
  let port = server.address().port;

  if (err) {
    log.error('something bad happened', err);
  } else if (process.env.NODE_ENV === 'test') {
     dbTest.connect();
  } else {
    db.connect();
  }

  log.info(`server is listening on ${port}`);
});

module.exports = server;
@@ -215,44 +215,8 @@
 t');
-%0Aconst cors       = require('cors');
 %0A%0Aco
@@ -708,24 +708,58 @@
 g/dbTest');%0A
+const cors    = require ('cors');%0A
 const db    
@@ -783,24 +783,24 @@
 onfig/db');%0A
-
 %0Aconst passp
@@ -897,24 +897,41 @@
 xpress ();%0A%0A
+app.use(cors());%0A
 app.use(pass
@@ -1017,24 +1017,24 @@
 : true %7D));%0A
+
 app.use(body
@@ -1052,26 +1052,8 @@
 ());
-%0Aapp.user(cors());
 %0A%0Aap

Add cors to server