/
web.rb
42 lines (31 loc) · 880 Bytes
/
web.rb
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
class FnordMetric::Web
def initialize(opts)
@opts = opts
@opts[:server] ||= "thin"
@opts[:host] ||= "0.0.0.0"
@opts[:port] ||= "4242"
FnordMetric.register(self)
end
def initialized
server = @opts[:server].downcase
websocket = FnordMetric::WebSocket.new
webapp = FnordMetric::App.new(@opts)
dispatch = Rack::Builder.app do
use Rack::CommonLogger
use Rack::ShowExceptions
map("/stream"){ run websocket }
map("/"){ run webapp }
end
unless ["thin", "hatetepe"].include? server
raise "Need an EventMachine webserver, but #{server} isn't"
end
host = @opts[:host]
port = @opts[:port]
Rack::Server.start(
:app => dispatch,
:server => server,
:Host => host,
:Port => port
) && FnordMetric.log("listening on http://#{host}:#{port}")
end
end