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
|
# File 'lib/kea/router.rb', line 10
def call(env)
@env = env
request = Rack::Request.new(env)
body = request.body.read
params = nil
if body.present?
params = JSON.parse(body).with_indifferent_access
request.body.rewind
else
if env['rack.request.form_vars'].present?
json_params = JSON.parse(env['rack.request.form_vars']) rescue nil
params = json_params.with_indifferent_access if json_params.present?
if params.blank? && env['rack.request.form_hash'].present?
params = env['rack.request.form_hash'].with_indifferent_access
end
end
end
@env['kea.params'] = params.with_indifferent_access
begin
@endpoint = params[:endpoint].classify.constantize
unless @endpoint.ancestors.include? Kea::Controller
return render_error({endpoint: 'does not descend from Kea::Controller'})
end
rescue => e
return render_error({exception: e.message})
end
@endpoint.action(:run_kea_action).call(env)
end
|