-
Notifications
You must be signed in to change notification settings - Fork 14
/
app.js
133 lines (111 loc) · 3.77 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
125
126
127
128
129
130
131
132
133
var path = require('path');
var nconf = require('nconf');
var config_path = process.env.OHE_CONFIG_PATH || path.join(__dirname, '/config.json');
var asset_map_path = process.env.OHE_ASSET_MAP_PATH || path.join(__dirname, '/asset_map.json');
nconf.argv().env('__').file({file: config_path});
nconf.add('asset_map', {type: 'file', file: asset_map_path});
var express = require('express');
var jade = require('jade');
var app = express();
var raven = require('raven');
var server = require('http').createServer(app);
var redisurl = require('./ohe/redisurl');
var RedisStore = require('connect-redis')(express);
var LightPoll = require('./ohe/lightpoll').LightPoll;
var adnstream = require('./ohe/adnstream');
var auth = require('./ohe/auth');
var adnproxy = require('./ohe/adnproxy');
var routes = require('./routes');
var _ = require('underscore');
var multiprocess = nconf.get('deploy:multiprocess');
var connect_to_stream = nconf.get('deploy:master') || !multiprocess;
var on_heroku = nconf.get('deploy:heroku');
var SENTRY_DSN = nconf.get('sentry:dsn');
if (on_heroku) {
nconf.set('sessions:redis_url', process.env.REDISTOGO_URL);
nconf.set('deploy:port', process.env.PORT);
}
var session_secret = nconf.get('sessions:secret');
var get_rcon = function () {
return redisurl.connect(nconf.get('sessions:redis_url'));
};
var session_store = new RedisStore({
client: get_rcon(),
ttl: 86400
});
var lightpoll = new LightPoll({
redis_client: get_rcon(),
pub_client: get_rcon(),
sub_client: get_rcon(),
timeout: nconf.get('lightpoll:timeout') || 10
});
var stream_router = require('./ohe/streamrouter').create_router(app, lightpoll);
app.configure(function () {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
});
var cookieParser = express.cookieParser(session_secret);
var secure = true;
app.configure('development', function () {
app.use(express.logger('dev'));
secure = false;
});
app.configure('production', function () {
app.use(express.logger());
});
app.configure(function () {
app.use(auth.ssl_middleware());
});
app.configure('production', function () {
app.use(auth.ssl_redirect_middleware());
});
app.configure(function () {
app.use(express.favicon());
app.use(express.methodOverride());
app.use(express.query());
app.use(cookieParser);
app.use(express.session({
key: nconf.get('sessions:cookie_name') || 'connect.sid',
store: session_store,
secret: session_secret,
proxy: true,
cookie: {
path:'/',
httpOnly: true,
secure: secure,
maxAge: 86400000,
domain: nconf.get('sessions:domain')
}
}));
app.use(auth.auth_middleware());
app.use(express.csrf());
app.use(adnproxy.middleware());
app.use(express.bodyParser());
app.use("/static", express['static'](__dirname + '/static'));
app.use(app.router);
app.use(raven.middleware.express(SENTRY_DSN));
app.use(express.errorHandler());
});
// Only connect to the actual stream if this is the master process
if (connect_to_stream) {
auth.get_app_token(function (token) {
stream_router.stream(token);
});
}
app.get('/', routes.index);
app.get('/muted', routes.index);
app.get('/channel/:channel_id', routes.index);
app.get('/new-message', routes.index);
app.get('/return', routes.oauth_return);
app.get('/logout', routes.logout);
app.get('/logout-and-login', routes.logout_and_login);
app.get('/healthcheck', routes.healthcheck);
app.get('/camofy-url', routes.camofy_url);
app.get('/file-url', routes.file_url);
lightpoll.enable(app);
server.listen(nconf.get('deploy:port') || 8666);
// Stash these for debugging purposes.
exports.app = app;
exports.server = server;
exports.nconf = nconf;
exports.lightpoll = lightpoll;