-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
72 lines (58 loc) · 1.76 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
var express = require("express");
var app = express();
var http = require("http").Server(app);
var raven = require("raven");
var io = require("socket.io")(http);
var redis = require("redis");
var env = process.env.NODE_ENV || "development";
var url = require("url");
var redisClient = null;
// Configuration
if (env === "production") {
// Sentry
app.use(raven.middleware.express(process.env.RAVEN_DNS));
// Redis
var redisConf = url.parse(process.env.REDISCLOUD_URL),
redisAuth = (redisConf.auth || '').split(':'),
redisPass = redisAuth[1];
redisClient = redis.createClient(redisConf.port, redisConf.hostname, {
no_ready_check: true,
auth_pass: redisPass,
});
redisClient.auth(redisPass);
} else if (env === "development") {
// Redis
redisClient = redis.createClient(6379, '127.0.0.1');
} else {
// Raise an error
console.error("Unknown env '" + env + "'");
}
// Ensure cross domain request support
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
// Redis pub/sub
redisClient.psubscribe("notification *");
redisClient.on("pmessage", function(pattern, channel, message) {
// broadcast the notification
if (channel === "notification signatures") {
io.emit("signatures", message);
} else {
console.error("unknown type of notification");
}
});
// Do you copy ?
app.get("/", function(req, res){
res.send("<h1>5 sur 5 Tango Charlie</h1>");
});
// Socket io
io.on("connection", function(socket){
// silence is golden
});
// Run the server
var port = process.env.PORT || 3000;
http.listen(port, function(){
console.log("listening on *:" + port);
});