-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (57 loc) · 2.23 KB
/
server.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
var Twitter = require('twitter'),
Ripley = require('./lib/ripley'),
Proxy = require('./lib/proxy'),
conffile = null, config = null;
// Configuration
if ( process.sparkEnv && process.sparkEnv.name )
var conffile = __dirname + '/config/' + process.sparkEnv.name + '.js';
try {
config = require(conffile);
} catch (error) {
console.error('Could not import ' + conffile + '!');
process.exit(1);
}
// Twitter (client for Routes and Ripley)
var twitter = Twitter(config.twitter || null);
twitter.options.secure = config.secure || false;
twitter.options.cookie_secret = config.secret || null;
twitter.options.cookie_options = {}; // httpOly fucks up flashsocket
// Ripley
var ripley = new Ripley(twitter, config);
// Web
module.exports = require('http').createServer(require('stack')(
require('creationix/log')(),
require('./lib/gzip-proc')(),
twitter.login(),
require('creationix/static')('/static', __dirname + '/static'),
twitter.gatekeeper(),
require('creationix/static')('/', __dirname + '/static', 'index.html')
));
// Socket.io
require('socket.io').listen(module.exports).on('connection', function(client) {
// Gatekeeper for Socket.io connections
var twauth = twitter.cookie(client.request);
//console.log('SOCKET.IO HEADERS: ' + require('util').inspect(client.request && client.request.headers));
// Success! Probably a valid cookie
if ( twauth && twauth.user_id && twauth.access_token_secret ) {
// Deliberately kill off non-alphas
if ( config.alphas && config.alphas.indexOf(twauth.screen_name.toLowerCase()) < 0 ) {
console.log('DUMPED NON-ALPHA ' + twauth.screen_name + '!');
client.send({AUTHFAIL: "Sorry, we're currently closed for alpha testing."});
/*setTimeout(function() {
if ( client.request ) client.request.connection.end();
}, 1000);*/
} else {
console.log('HELLO ' + twauth.screen_name + '!');
var ripper = ripley.register(twauth);
new Proxy(client, ripper);
}
// Fail! Computer says no. Client might fall back to other socket.io transports.
} else {
console.log('DUMPED ' + (twauth && twauth.screen_name || 'unauthenticated user') + '!');
client.send({AUTHFAIL: "Authentication failure."});
/*setTimeout(function() {
if ( client.request ) client.request.connection.end();
}, 1000);*/
}
});