-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
37 lines (30 loc) · 1.04 KB
/
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
33
34
35
36
37
'use strict';
const config = require('./config');
const _ = require('underscore');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const path = require('path');
const favicon = require('serve-favicon');
const express = require('express');
const jsonResponse = require('./utils/json-response');
const index = require('./routes/index');
const errors = require('./helpers/errors');
const app = express();
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({extended: true, limit: '50mb'}));
app.use(morgan('dev'));
app.use('/', index);
/* Routes classifications */
app.use((req, res) => {
if (config.mode === 'development') {
console.log('Error: No route found or Wrong method name');
jsonResponse(res, errors.resourceNotFound(false), null);
} else {
jsonResponse(res, errors.resourceNotFound(true), null);
}
});
app.use(express.static(path.join(__dirname, 'public')));
let port = process.env.PORT || config.port;
app.listen(port, () => {
console.log('Listening on port ' + port);
});