Slide 19
Slide 19 text
module Helper
include Dashboard::RedisHelper
def response(env)
http_method = env['REQUEST_METHOD'].downcase
return cors_options if http_method == 'options'
invoke_api_using http_method
end
def publish(resource)
event = { app_name: resource.class.app_name,
ignore: current_user[:id],
payload: resource }
redis.publish 'dashboard', event.to_json
end
private
def invoke_api_using(http_method)
response = send(http_method)
[200, cors_headers, response]
end
def cors_headers
{ 'Access-Control-Allow-Origin' => env['HTTP_ORIGIN'],
'Access-Control-Allow-Methods' => 'GET, PUT, POST, DELETE, OPTIONS',
'Access-Control-Allow-Headers' => 'Content-Type, Depth, User-Agent, X-
Requested-With, Cache-Control',
'Access-Control-Allow-Credentials' => 'true' }
end
end