-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
62 lines (47 loc) · 1.33 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
var express = require('express'),
fs = require('fs'),
yamlConfig = require('yaml-config'),
auth = require('./authorization'),
settings = require('./settings'),
modelsPath = __dirname + '/app/models',
modelFiles = fs.readdirSync(modelsPath),
controllersPath = __dirname + '/app/controllers',
controllerFiles = fs.readdirSync(controllersPath),
port,
app;
//globals
config = yamlConfig.readConfig('config/app.yml');
User = {};
//setting up connection to mongodb
require('./db-connect');
//bootstrap models
modelFiles.forEach(function (file) {
'use strict';
if (file == 'user.js') {
User = require(modelsPath + '/' + file);
} else {
require(modelsPath + '/' + file);
}
});
//booting app
app = express.createServer();
settings.boot(app);
//bootstrap controllers
controllerFiles.forEach(function (file) {
'use strict';
require(controllersPath + '/' + file)(app, auth);
});
//loading chat module
require('./app/modules/chat')(app);
app.get('/', function (req, res) {
'use strict';
if (req.loggedIn) {
res.render('index', {layout: false, user: req.user});
} else {
res.render('login', {layout: false});
}
});
mongooseAuth.helpExpress(app);
everyauth.helpExpress(app, {userAlias: 'current_user'});
port = process.env.PORT || 8080;
app.listen(port);