-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
60 lines (52 loc) · 2.7 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
var log = require("log4js-config").get("net.renalias.yamer.wall.app"),
//log = require("app-logger").get("net.renalias.yammer.wall.app"),
express = require('express'),
app = express.createServer(),
port = process.env.PORT || 8081,
config = require('./config.js'),
util = require('util'),
PushAPIClient = require('./lib/apiclient');
// configure Express
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
// access log is a bit too chatty, let's switch it off during developmet
if(config.mode() == "prod") {
// Tell Express to use the log4js logger
//var log4js = require("log4js");
//app.use(require("app-logger").log4js.getLogger("net.renalias.yammer.wall.http"));
app.use(require("log4js-config").get("net.renalias.yammer.wall.http"));
}
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session({ secret: '*#sURcTCeALkyJPhCv$dCk*d@rav4*A$' }));
// Dynamically configure authentication. The nasty part is that we're passing the 'app' object
// by reference and modifying it in the auth configuration module... should find a better way to do it
require("./lib/auth/auth." + config.auth.type + ".js")(app, config);
app.use(app.router);
// Tell the Express framework where to find our static files
app.use(express.static(__dirname + '/public'));
});
// RESTful JSON routes with the statistics
// TODO: we can probably replace all these hand-coded routes with a catch-all /stats/collections/:coll-id
// and with a smarter router/controller that will know to which collection to route it
var statsRoutes = require('./routes/routes.stats.js')(config)
app.get("/stats/collections/top_users", statsRoutes.top_users)
app.get("/stats/collections/top_topics", statsRoutes.top_topics)
app.get("/stats/collections/top_threads", statsRoutes.top_threads)
app.get("/stats/collections/top_clients", statsRoutes.top_clients)
app.get("/stats/collections/hourly_activity", statsRoutes.hourly_activity)
app.get("/stats/collections/daily_activity", statsRoutes.daily_activity)
app.get("/stats/data/recent", statsRoutes.recent);
app.get("/stats", statsRoutes.ui)
// connect and set up the handlers
var pushAPIClient = PushAPIClient(config);
pushAPIClient.on("data", require('./lib/handlers/clients').handler(config, app));
pushAPIClient.on("data", require('./lib/handlers/diskwriter').handler(config, app));
pushAPIClient.on("data", require('./lib/analytics/handler').handler(config, app));
pushAPIClient.on("fatal", require('./lib/handlers/fatal.js').handler(config, app));
pushAPIClient.start();
// start the application
app.listen(port);
log.info("Server started in port: " + port);