This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
/
app.js
73 lines (60 loc) · 1.87 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
63
64
65
66
67
68
69
70
71
72
73
'use strict';
var zmq = require('zmq');
var express = require('express');
var configurations = module.exports;
var app = express();
var server = require('http').createServer(app);
var nconf = require('nconf');
var passport = require('passport');
var TwitterStrategy = require('passport-twitter').Strategy;
var settings = require('./settings')(app, configurations, express);
nconf.argv().env().file({ file: 'local.json' });
/* Passport OAuth setup */
passport.serializeUser(function (user, done) {
done(null, user);
});
passport.deserializeUser(function (obj, done) {
done(null, obj);
});
passport.use(new TwitterStrategy({
consumerKey: nconf.get('twitter_key'),
consumerSecret: nconf.get('twitter_secret'),
callbackURL: nconf.get('domain') + ':' + nconf.get('authPort') + '/auth/twitter/callback'
},
function (accessToken, refreshToken, profile, done) {
process.nextTick(function (err) {
if (!profile.access_token) {
profile.access_token = accessToken;
}
return done(err, profile);
});
}
));
var isLoggedIn = function (req, res, next) {
if (req.session.authenticated) {
next();
} else {
res.status(403);
res.json({
error: 'You need to be authenticated'
});
}
};
// set up meatcounter publisher and connect
// to endpoints
var meatcounter_addrs = nconf.get('meatcounter_addrs');
var zio = zmq.socket('pub');
for (var i = 0; i < meatcounter_addrs.length; i ++) {
zio.connect(meatcounter_addrs[i]);
}
var topic_in = nconf.get('meatcounter_inc_topic');
var topic_out = nconf.get('meatcounter_out_topic');
// set up websocket
var io = require('socket.io').listen(server);
io.configure(function () {
io.set('transports', ['websocket']);
io.set('log level', 1);
});
// routes
require('./routes')(app, nconf, io, zio, topic_in, topic_out, passport, isLoggedIn);
server.listen(process.env.PORT || nconf.get('port'));