From a176fea6d081263b93a122ba5f377b8d21c19722 Mon Sep 17 00:00:00 2001 From: rautenberg Date: Wed, 20 May 2015 18:05:11 +0200 Subject: add basic CORS headers get, post, put --- lib/opentox-server.rb | 1 + lib/opentox.rb | 11 +++++++++++ opentox-server.gemspec | 1 + 3 files changed, 13 insertions(+) diff --git a/lib/opentox-server.rb b/lib/opentox-server.rb index 5ff3c22..0202b44 100644 --- a/lib/opentox-server.rb +++ b/lib/opentox-server.rb @@ -1,5 +1,6 @@ require 'opentox-client' require 'rack' require 'rack/contrib' +require 'rack/cors' require 'sinatra' ["4store.rb", "opentox.rb", "authorization-helper.rb"].each {|f| require File.join(File.dirname(__FILE__),f) } diff --git a/lib/opentox.rb b/lib/opentox.rb index bd5415c..2adc04c 100644 --- a/lib/opentox.rb +++ b/lib/opentox.rb @@ -27,6 +27,17 @@ module OpenTox also_reload File.join(ENV["HOME"],".opentox","config","#{SERVICE}.rb") end + # add CORS support for swagger + use Rack::Cors do |config| + config.allow do |allow| + allow.origins '*' + allow.resource "/#{SERVICE}/*", + :methods => [:get, :post, :put ], + :headers => :any, + :max_age => 0 + end + end + before do @uri = uri(request.env['PATH_INFO']) # prevent /algorithm/algorithm in algorithm service get_subjectid if respond_to? :get_subjectid diff --git a/opentox-server.gemspec b/opentox-server.gemspec index cc9d160..a38a860 100644 --- a/opentox-server.gemspec +++ b/opentox-server.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency "opentox-client" s.add_runtime_dependency 'rack' s.add_runtime_dependency 'rack-contrib' + s.add_runtime_dependency 'rack-cors' s.add_runtime_dependency 'sinatra' s.add_runtime_dependency 'sinatra-contrib' s.add_runtime_dependency 'unicorn' -- cgit v1.2.3