All files / server app.js

81.48% Statements 22/27
33.33% Branches 2/6
0% Functions 0/3
84.62% Lines 22/26
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 421x 1x 1x 1x   1x 1x 1x 1x   1x   1x   1x 1x   1x 1x   1x 1x 1x     1x 1x     1x             1x       1x  
const bodyParser = require('body-parser');
const cors = require('cors');
const express = require('express');
const path = require('path');
 
const config = require('../config');
const api = require('./api');
const db = require('./db');
const { logger: expressLogger } = require('./utils/express');
 
const logger = config.logger('app');
 
const app = express();
 
app.set('db', db);
app.set('env', config.env);
 
app.use(expressLogger);
app.use(bodyParser.json());
 
logger.debug(`CORS is ${config.cors ? 'enabled' : 'disabled'} (change with $CORS or config.cors)`);
Eif (config.cors) {
  app.use(cors());
}
 
app.use('/api', api);
app.use('/', (req, res) => res.send('biopocket'));
 
// 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) => {
  res.status(err.status || 500).send(`Error: ${err.message}`);
});
 
module.exports = app;