Skip to content

Commit

Permalink
experiment cors headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Apr 1, 2016
1 parent 44ec64f commit 95530dd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/apiv1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ def check_authorization
def get_facts(base, node)
Hieraviz::Facts.new(settings.configdata['tmpdir'], base, node, username)
end
def cors_headers()
headers 'Access-Control-Allow-Origin' => '*'
headers 'Access-Control-Allow-Headers' => 'Authorization,Accepts,Content-Type,X-CSRF-Token,X-Requested-With'
headers 'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS'
end
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/nodes} do |base|
Expand Down Expand Up @@ -108,6 +113,7 @@ def get_facts(base, node)
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/farms} do |base|
cors_headers
check_authorization
hieracles_config = prepare_config(base)
json Hieracles::Registry.farms_counted(hieracles_config, base)
Expand Down Expand Up @@ -138,6 +144,7 @@ def get_facts(base, node)
end

get %r{^/?([-_\.a-zA-Z0-9]+)?/farm/([-_\.a-zA-Z0-9]+)$} do |base, farm|
cors_headers
check_authorization
hieracles_config = prepare_config(base)
nodes = Hieracles::Registry.nodes_data(hieracles_config, base).each_with_object({}) do |(key, val), acc|
Expand Down

0 comments on commit 95530dd

Please sign in to comment.