forked from BarkingMouseStudio/reddish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
124 lines (96 loc) · 3.42 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Generated by CoffeeScript 1.3.3
(function() {
var Client, Endpoint, RedisStore, app, ca, cert, certs, connections_del, connections_get, connections_post, endpoint_ports, express, io, key, md5, monitor_endpoint_port, options, path, port, redis, secure, session_secret, socketio, standard_endpoint_port, stylus, _ref, _ref1;
path = require('path');
stylus = require('stylus');
io = require('socket.io');
express = require('express');
RedisStore = require('connect-redis')(express);
redis = require('./lib/common').redis;
_ref = require('./lib/config'), session_secret = _ref.session_secret, port = _ref.port, endpoint_ports = _ref.endpoint_ports, secure = _ref.secure;
md5 = require('./lib/utils').md5;
if (secure) {
certs = require('./certs');
}
app = secure ? express.createServer(certs) : express.createServer();
app.configure(function() {
var public_path, src_path, store;
public_path = path.join(__dirname, 'public');
src_path = path.join(__dirname, 'src');
this.use(stylus.middleware({
debug: true,
src: src_path,
dest: public_path,
compile: function(str) {
return stylus(str).set('compress', true);
}
}));
this.use(express.bodyParser());
this.use(express.cookieParser());
this.use(express.query());
this.use(express.session({
secret: session_secret,
store: store = new RedisStore({
client: redis,
prefix: 'session:'
}),
cookie: {
path: '/',
httpOnly: true,
maxAge: 1000 * 60 * 60 * 24,
secure: secure
}
}));
this.use(express.favicon(path.join(public_path, 'favicon.png')));
this.use(express["static"](public_path, {
maxAge: 1000 * 60 * 60 * 24
}));
this.use(express.errorHandler({
stack: true,
message: true,
dump: true
}));
return this.use(express.logger('dev'));
});
_ref1 = require('./lib/routes'), connections_get = _ref1.get, connections_post = _ref1.post, connections_del = _ref1.del;
app.get('/connections', connections_get);
app.post('/connections', connections_post);
app.del('/connections/:id', connections_del);
app.listen(port);
console.log("Running at http://localhost:" + port);
socketio = require('socket.io');
io = socketio.listen(app);
io.configure(function() {
var handle_auth;
this.set('log level', 2);
return this.set('authorization', handle_auth = function(data, callback) {
var sessionId, _ref2, _ref3;
if (!(sessionId = (_ref2 = data.headers) != null ? (_ref3 = _ref2.cookie) != null ? _ref3.replace(/.*connect.sid=(.+)(?:;|$)/, '$1') : void 0 : void 0)) {
callback(new Error("session:invalid:" + sessionId), false);
return;
}
data.sessionId = decodeURIComponent(sessionId);
return callback(null, true);
});
});
Client = require('./lib/redis/Client');
io.sockets.on('connection', function(socket) {
return new Client(socket);
});
Endpoint = require('./lib/endpoint');
standard_endpoint_port = endpoint_ports[0], monitor_endpoint_port = endpoint_ports[1];
if (secure) {
key = certs.key, cert = certs.cert, ca = certs.ca;
options = {
key: key,
cert: cert,
ca: [ca]
};
} else {
options = {
allowHalfOpen: true
};
}
new Endpoint(standard_endpoint_port, 'STANDARD', secure, options);
new Endpoint(monitor_endpoint_port, 'MONITOR', secure, options);
}).call(this);