diff options
Diffstat (limited to 'lib/lazar-rest.rb')
-rw-r--r-- | lib/lazar-rest.rb | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/lib/lazar-rest.rb b/lib/lazar-rest.rb index 77483f2..41010e1 100644 --- a/lib/lazar-rest.rb +++ b/lib/lazar-rest.rb @@ -1,4 +1,13 @@ require "sinatra" +require "sinatra/reloader" +require 'sinatra/cross_origin' + +configure do + enable :reloader if development? + enable :cross_origin +end + +#set :protection, :except => :frame_options # Environment setup from unicorn -E param ENV["LAZAR_ENV"] = ENV["RACK_ENV"] @@ -12,14 +21,12 @@ else end include OpenTox - -require 'rack/cors' +#require 'rack/cors' set :show_exceptions => false - +=begin # add CORS support for swagger -use Rack::Cors do |config| config.allow do |allow| allow.origins '*' allow.resource "/#{SERVICE}/*", @@ -28,11 +35,21 @@ use Rack::Cors do |config| :max_age => 0 end end +=end before do - @accept = request.env['HTTP_ACCEPT'] + @accept = request.env['HTTP_ACCEPT'].split.last response['Content-Type'] = @accept end +# https://github.com/britg/sinatra-cross_origin#responding-to-options +options "*" do + response.headers["Allow"] = "HEAD,GET,PUT,POST,DELETE,OPTIONS" + response.headers["Access-Control-Allow-Headers"] = "X-Requested-With, X-HTTP-Method-Override, Content-Type, Cache-Control, Accept" + 200 +end + + + [ "aa.rb", "api.rb", @@ -43,5 +60,6 @@ end "nanoparticle.rb", "report.rb", "substance.rb", + "swagger.rb", "validation.rb" ].each{ |f| require_relative f } |