Class: FrCable::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/fr_cable/rack.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



5
6
7
8
# File 'lib/fr_cable/rack.rb', line 5

def initialize app
  @app = app
  @http_handler = ::FrCable::HttpHandler.new
end

Class Method Details

.configObject



10
11
12
13
14
# File 'lib/fr_cable/rack.rb', line 10

def self.config
  @config = {
    socket_server_url: 'http://localhost:3015/http'
  }
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fr_cable/rack.rb', line 16

def call(env) 
  if env["REQUEST_PATH"] == "/fr_cable_connection" && env["REQUEST_METHOD"] == "POST"
    hash = env['rack.input'].read
    params = JSON.parse hash
    @http_handler.send(params["type"], params["payload"])
    [200, {}, params.to_json]
  else
    @status, @headers, @response = @app.call(env)
    [@status, @headers, @response]
  end
end