-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (23 loc) · 859 Bytes
/
app.js
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
const express = require('express');
const bodyParser = require('body-parser');
const routes = require('./routes/index');
const authHandlers = require('./handlers/authHandler');
const errorHandlers = require('./handlers/errorHandler');
// Create the Express app
const app = express();
// Takes the raw requests and turns them into usable properties on req.body
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
// Basic authentication
app.use(authHandlers.validation);
// Routes handler
app.use('/v1', routes);
// If routes didn't work, throw 404 error and forward to error handler
app.use(errorHandlers.notFound);
// Development error handler
if (app.get('env') === 'development') {
app.use(errorHandlers.developmentErrors);
}
// Production error handler
app.use(errorHandlers.productionErrors);
module.exports = app;