-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (45 loc) · 1.31 KB
/
index.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
var express = require('express');
var bodyParser = require('body-parser');
var helmet = require('helmet');
var compression = require('compression');
var utils = require('./libs/utils.lib');
var config = require('./config');
var app = express();
var apiRoutes = require('./routes/main');
var mongoose = require('mongoose');
app.disable('x-powered-by');
/**
* Setting the system startup mode.
* It can be: test, dev or production.
*/
let startUpMode = utils.getStartUpMode();
if(startUpMode === 'PRODUCTION') {
mongoose.connect(config.MONGO_DB_PRODUCTION);
} else if(startUpMode === 'TEST') {
mongoose.connect(config.MONGO_DB_TEST);
utils.bootstrapCollections(app);
} else {
mongoose.connect(config.MONGO_DB_DEV);
}
// Setting body parser
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// Setting helmet
app.use(helmet());
// Setting compression - G-Zip
app.use(compression());
/**
* Setting up the routes configs
*/
app.use('/', apiRoutes);
/**
* Start server if it's in production or dev mode
* In 'test' mode, the server is started after
* setup the collections by bootstrapCollections
* function.
*/
if(startUpMode === 'PRODUCTION' || startUpMode === 'DEV') {
app.listen(config.SERVER_PORT, function() {
console.log(`Express started on port ${port}, on ${startUpMode} mode.`);
});
}