-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·42 lines (32 loc) · 1.15 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
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var app = require('express')();
var bodyParser = require('body-parser');
var jsonAdapters = require('./utils/jsonAdapters');
var path = require('path');
var swig = require('swig');
// View engine setup
app.engine('html', swig.renderFile);
app.set('view engine', 'html');
app.set('views', __dirname + '/view');
app.set('view cache', false);
swig.setDefaults({ cache: false });
app.use(bodyParser.json());
GLOBAL.rootDirName = __dirname;
var MONGO_DB = process.env.MONGODB;
var DOCKER_DB = process.env.DB_PORT;
if (DOCKER_DB) {
MONGO_DB = DOCKER_DB.replace( 'tcp', 'mongodb' ) + '/easyrouter';
}
mongoose.connect(MONGO_DB);
require('./entities');
var restController = require('./controllers/restController');
restController.initMethods(app);
var viewController = require('./controllers/viewController');
viewController.initMethods(app, __dirname);
var serverPort = process.env.PORT || 3000;
var server = app.listen(serverPort, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Easy router listening at http://%s:%s', host, port);
});