-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
44 lines (35 loc) · 1019 Bytes
/
index.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
var http = require('http')
var fs = require('fs')
var path = require('path')
var subscribe = require('redis-subscribe-sse')
var port = process.env.PORT || 3000
var redis_host = process.env.REDIS_HOST
var redis_port = process.env.REDIS_PORT
var redis_pass = process.env.REDIS_PASS
// http server
var server = http.createServer(function(req, res) {
if (matches = req.url.match(/^\/([^\/]+)\/([^\/]+)$/)) {
var owner = matches[1]
var module = matches[2]
var channel = "babl:log:module:" + owner + '/' + module
var sse = subscribe({
channels: [channel],
host: redis_host,
port: redis_port,
clientOptions: {
auth_pass: redis_pass
}
})
req.setTimeout(0)
res.setHeader('Content-Type', 'text/event-stream')
res.setHeader('Cache-Control', 'no-cache')
res.setHeader('Connection', 'keep-alive')
sse.pipe(res).on('close', function() {
sse.close()
})
} else {
res.statusCode = 404
res.end("404")
}
})
server.listen(port)