-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
46 lines (37 loc) · 1.16 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
var express = require('express');
var configurations = module.exports;
var app = express();
var server = require('http').createServer(app);
var nconf = require('nconf');
var settings = require('./settings')(app, configurations, express);
var whitelist = require('./whitelist');
var Meatspace = require('meatspace-leveldb');
nconf.argv().env().file({ file: 'local.json' });
var io = require('socket.io').listen(server);
io.configure(function () {
io.set('transports', ['websocket', 'xhr-polling']);
io.set('polling duration', 10);
io.set('log level', 1);
});
/* Filters for routes */
var isLoggedIn = function(req, res, next) {
if (req.session.email && whitelist.indexOf(req.session.email) > -1) {
next();
} else {
res.status(400);
next(new Error('Invalid login'));
}
};
var meat = new Meatspace({
fullName: nconf.get('full_name'),
username: nconf.get('username'),
postUrl: nconf.get('url'),
db: nconf.get('db'),
limit: 13
});
require('express-persona')(app, {
audience: nconf.get('domain') + ':' + nconf.get('authPort')
});
// routes
require('./routes')(app, io, meat, isLoggedIn, nconf);
server.listen(process.env.PORT || nconf.get('port'));