-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
86 lines (77 loc) · 2.33 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
"use strict";
//set The GLOBALS;
require('./bootstrap.js').init();
var express = require('express');
var cors = require('cors')
var app = express();
var routesApi = require('./app/routes-api');
var routesWeb = require('./app/routes-web');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var sessionFactory = require('./lib/session');
var expressLayouts = require('express-ejs-layouts');
var grunt = require("grunt");
//Server settings;
app.use(express.static(__dirname));
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(sessionFactory());
app.use(cors());
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.set('layout', 'layouts/html_app');
app.set('port', config.server.port);
app.use(expressLayouts);
app.use(function(req, res, next) {
//defaults variables;
res.locals.login = false;
res.locals.environment = global.config['environment'];
res.locals.npm_package_name = global.config['npm_package_name'];
if (typeof req.session.user != 'undefined') {
res.locals.login = true;
}
next();
});
routesWeb.setup(app);
routesApi.setup(app);
var _addWatcher = function() {
grunt.cli({
gruntfile: __dirname + "/Grunt_dev.js",
extra: {
key: "run"
}
});
}
var _launchApp = function() {
//init database and starts server after the init;
global.models.sequelize.sync().then(function() {
try {
app.listen(app.get('port'), function() {
logger.info('Loaded configuration: \n' + JSON.stringify(getUtil.inspect(config)));
logger.info('Server started in ' + config.environment + ' mode.');
logger.info('Listening on port: ' + app.get('port'));
});
} catch (err) {
logger.log('Error', 'Failed to start express', { error: err });
}
});
}
if (global.config.environment === 'production') {
logger.warn('Creating the build, please wait...');
grunt.cli({
gruntfile: __dirname + "/Grunt_pro.js",
extra: {
key: "run"
}
}, function() {
//callback;
_launchApp();
});
} else {
logger.info('Bypassing build we are in ' + global.config.environment + ' please wait...');
_addWatcher();
_launchApp();
}