-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
63 lines (51 loc) · 1.74 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* Created by Rohit Raj.
* Date: 15/8/18
* Version : v1.0
*/
process.env.NODE_CONFIG_DIR = __dirname + '/config/';
const config = require('config');
// Adding the new relic server monitoring if enabled : this is not enabled for now
if (config.get('newRelicEnabled')) {
require('newrelic');
}
var express = require('express');
var logger = require('morgan');
var bodyParser = require('body-parser');
var errorhandler= require('errorhandler');
var http = require('http');
//Exports file and function
var validator = require('./middleware/validator').validateLogin; //Middleware to validate login
var users = require('./routes/usersController');
var inventory = require('./routes/inventoryController');
var activity = require('./routes/activityController');
var app = express();
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// production only
if ('production' === app.get('env')) {
app.use(function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
} else {
console.log("test");
app.use(errorhandler());
}
/**--------------------------------------------------------
* AUTHORIZATION
*---------------------------------------------------------
*/
app.use('/v1/auth', users);
app.use('/v1/inventory', validator(), inventory);
app.use('/v1/activity', activity);
module.exports = app;
http.createServer(app).listen(config.get('port'), function () {
console.log('Express server started on port');
console.log('http://localhost:' + config.get('port'));
console.log('http://127.0.0.1:' + config.get('port'));
});