|
|
|
@ -18,6 +18,7 @@ methods.start = () => {
|
|
|
|
|
// init express framework
|
|
|
|
|
let express = require('express');
|
|
|
|
|
let session_handler = require('express-session');
|
|
|
|
|
let session_store = require('connect-mongo')(session_handler);
|
|
|
|
|
|
|
|
|
|
// utilities
|
|
|
|
|
let fs = require('fs');
|
|
|
|
@ -86,18 +87,34 @@ methods.start = () => {
|
|
|
|
|
if(app.get('env') === 'debug')
|
|
|
|
|
app.locals.pretty = true;
|
|
|
|
|
|
|
|
|
|
// Sessions
|
|
|
|
|
session_options = {
|
|
|
|
|
secret: cfg.web.sessionKey,
|
|
|
|
|
resave: false,
|
|
|
|
|
saveUninitialized: false, cookie: {}};
|
|
|
|
|
if(app.get('env') === 'production') {
|
|
|
|
|
session_options.cookie.secure = true;
|
|
|
|
|
}
|
|
|
|
|
app.use(session_handler(session_options));
|
|
|
|
|
|
|
|
|
|
// web routes
|
|
|
|
|
(async function() {
|
|
|
|
|
// mongooseConnection
|
|
|
|
|
let db = global['requireModule']('database');
|
|
|
|
|
await db.connect();
|
|
|
|
|
let con = db.getConnection();
|
|
|
|
|
|
|
|
|
|
// Sessions
|
|
|
|
|
session_options = {
|
|
|
|
|
secret: cfg.web.sessionKey,
|
|
|
|
|
resave: false,
|
|
|
|
|
saveUninitialized: false,
|
|
|
|
|
cookie: {
|
|
|
|
|
maxAge: cfg.web.cookieMaxAge
|
|
|
|
|
},
|
|
|
|
|
store: new session_store({
|
|
|
|
|
mongooseConnection: con,
|
|
|
|
|
dbName: cfg.mongoose.db,
|
|
|
|
|
ttl: cfg.web.cookieMaxAge,
|
|
|
|
|
secret: (app.get('env') === 'production') ? true : false
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
if(app.get('env') === 'production') {
|
|
|
|
|
app.set('trust proxy', 1);
|
|
|
|
|
session_options.cookie.secure = true;
|
|
|
|
|
}
|
|
|
|
|
app.use(session_handler(session_options));
|
|
|
|
|
|
|
|
|
|
// web routes
|
|
|
|
|
let mRoutes = require(global['__dirname']+'/bin/web/routes/static');
|
|
|
|
|
let mainRoutes = await mRoutes.getRoutes();
|
|
|
|
|
app.use('/', mainRoutes);
|
|
|
|
@ -106,9 +123,14 @@ methods.start = () => {
|
|
|
|
|
app.use('/api', restAPI);
|
|
|
|
|
|
|
|
|
|
// start server
|
|
|
|
|
app.listen(cfg.web.port, () => {
|
|
|
|
|
global['logs'].log("Server is listening on port: "+cfg.web.port);
|
|
|
|
|
});
|
|
|
|
|
if(app.get('env') === 'production' && cfg.web.host && typeof cfg.web.host == "string")
|
|
|
|
|
app.listen(cfg.web.port, cfg.web.host, () => {
|
|
|
|
|
global['logs'].log("Server is listening on port: "+cfg.web.port);
|
|
|
|
|
});
|
|
|
|
|
else if(app.get('env') === 'debug' || !cfg.web.host || typeof cfg.web.host !== "string")
|
|
|
|
|
app.listen(cfg.web.port, () => {
|
|
|
|
|
global['logs'].log("Server is listening on port: "+cfg.web.port);
|
|
|
|
|
});
|
|
|
|
|
})();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|