'use strict';

if (process.env.NODE_ENV !== 'production') {
  require('dotenv').config({ silent: true });
}

const express = require('express');
const path = require('path');
const port = process.env.PORT || 8000;

const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser');
const cookieSession = require('cookie-session');

const authors = require('./routes/authors');
const books = require('./routes/books');
const session = require('./routes/session');
const users = require('./routes/users');
const users_books = require('./routes/users_books');

const app = express();

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

if (process.env.NODE_ENV !== 'test') {
  const morgan = require('morgan');
  app.use(morgan('short'));
}

app.use(bodyParser.json());
app.use(cookieParser());
app.use(cookieSession({
  name: 'bookshelf',
  secret: process.env.SESSION_SECRET
}));

app.use(express.static(path.join('public')));

app.use(authors);
app.use(books);
app.use(session);
app.use(users);
app.use(users_books);

app.use((_req, res) => {
  res.sendStatus(404);
});

// eslint-disable-next-line max-params
app.use((err, _req, res, _next) => {
  // eslint-disable-next-line no-console
  console.error(err.stack);
  res.sendStatus(500);
});

app.listen(port, () => {
  if (process.env.NODE_ENV !== 'test') {
    // eslint-disable-next-line no-console
    console.log('Listening on port', port);
  }
});

module.exports = app;

@@ -84,24 +84,8 @@
 fig(
-%7B silent: true %7D
 );%0A%7D
@@ -132,127 +132,66 @@
 nst 
-path = require('path');%0Aconst port = process.env.PORT %7C%7C 8000;%0A%0Aconst bodyParser = require('body-parser
+app = express();%0A%0Aapp.disable('x-powered-by
 ');%0A
+%0A
 const 
-cookie
+body
 Pars
@@ -204,22 +204,20 @@
 equire('
-cookie
+body
 -parser'
@@ -272,22 +272,20 @@
 ');%0A
-%0A
 const 
-authors
+morgan
  = r
@@ -296,338 +296,130 @@
 re('
-./routes/authors');%0Aconst books = require('./routes/books');%0Aconst session = require('./routes/session');%0Aconst users = require('./routes/users');%0Aconst users_books = require('./routes/users_books');%0A%0Aconst app = express();%0A%0Aapp.disable('x-powered-by');%0A%0Aif (process.env.NODE_ENV !== 'test') %7B%0A  const morgan = require('morgan');%0A
+morgan');%0A%0Aswitch (app.get('env')) %7B%0A  case 'development':%0A    app.use(morgan('dev'));%0A    break;%0A%0A  case 'production':%0A  
   ap
@@ -442,16 +442,39 @@
 ort'));%0A
+    break;%0A%0A  default:%0A
 %7D%0A%0Aapp.u
@@ -500,33 +500,8 @@
 ));%0A
-app.use(cookieParser());%0A
 app.
@@ -581,80 +581,440 @@
 CRET
-%0A%7D));%0A%0Aapp.use(express.static(path.join('public')));%0A%0Aapp.use(autho
+,%0A  secureProxy: app.get('env') === 'production'%0A%7D));%0A%0Aconst path = require('path');%0A%0Aapp.use(express.static(path.join('public')));%0A%0Aapp.use((req, res, next) =%3E %7B%0A  if (/json/.test(req.get('Accept'))) %7B%0A    return next();%0A  %7D%0A%0A  res.sendStatus(406);%0A%7D);%0A%0Aconst books = require('./routes/books');%0Aconst favorites = require('./routes/favorites');%0Aconst session = require('./routes/session');%0Aconst users = require('./routes/use
 rs
+'
 );%0A
+%0A
 app.
@@ -1021,24 +1021,44 @@
 use(books);%0A
+app.use(favorites);%0A
 app.use(sess
@@ -1082,30 +1082,8 @@
 rs);
-%0Aapp.use(users_books);
 %0A%0Aap
@@ -1209,16 +1209,185 @@
 t) =%3E %7B%0A
+  if (err.output && err.output.statusCode) %7B%0A    return res%0A      .status(err.output.statusCode)%0A      .set('Content-Type', 'text/plain')%0A      .send(err.message);%0A  %7D%0A%0A
   // esl
@@ -1471,24 +1471,64 @@
 (500);%0A%7D);%0A%0A
+const port = process.env.PORT %7C%7C 8000;%0A%0A
 app.listen(p
@@ -1546,36 +1546,30 @@
 %7B%0A  if (
-process.env.NODE_ENV
+app.get('env')
  !== 'te

Update server.js file