diff options
author | gebele <gebele@in-silico.ch> | 2017-06-08 17:30:34 +0000 |
---|---|---|
committer | gebele <gebele@in-silico.ch> | 2017-06-08 17:30:34 +0000 |
commit | 02a48a009f1a241102ce760feb9376ae04f81f7f (patch) | |
tree | af790fab98aec054977616b994dc3474e1ecd4da | |
parent | e7d5c591f7e58631cab0694deb981497c99f5cc4 (diff) | |
parent | 31eccd98440dd9b28580ae9e1961ab738dc79823 (diff) |
fixed merge
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | lazar-rest.gemspec | 3 | ||||
-rw-r--r-- | lib/lazar-rest.rb | 28 | ||||
-rw-r--r-- | lib/model.rb | 2 | ||||
-rw-r--r-- | lib/report.rb | 4 | ||||
-rw-r--r-- | lib/swagger.rb | 8 |
6 files changed, 39 insertions, 10 deletions
@@ -1,6 +1,8 @@ source "https://rubygems.org" gemspec gem "sinatra" +gem "sinatra-reloader" +gem "sinatra-cross_origin", "~> 0.3.1" gem "haml" gem "sass" -gem "lazar", :path => "../lazar"
\ No newline at end of file +gem "lazar", :path => "../lazar" diff --git a/lazar-rest.gemspec b/lazar-rest.gemspec index 4aaeb14..dc0b07c 100644 --- a/lazar-rest.gemspec +++ b/lazar-rest.gemspec @@ -19,8 +19,9 @@ Gem::Specification.new do |s| s.add_runtime_dependency "lazar" s.add_runtime_dependency "qsar-report" s.add_runtime_dependency "sinatra" + s.add_runtime_dependency "sinatra-cross_origin", "~> 0.3.1" s.add_runtime_dependency "haml" s.add_runtime_dependency "sass" s.add_runtime_dependency "unicorn" - s.add_runtime_dependency 'rack-cors' + #s.add_runtime_dependency 'rack-cors' end 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 } diff --git a/lib/model.rb b/lib/model.rb index a20850b..22094e9 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -3,7 +3,7 @@ # @param [Header] Accept one of text/uri-list, # @return [text/uri-list] list of all prediction models get "/model/?" do - models = Model::Prediction.all + models = Model::Validation.all case @accept when "text/uri-list" uri_list = models.collect{|model| uri("/model/#{model.model_id}")} diff --git a/lib/report.rb b/lib/report.rb index 71c2045..52cced1 100644 --- a/lib/report.rb +++ b/lib/report.rb @@ -2,7 +2,7 @@ # @param [Header] Accept one of text/uri-list, # @return [text/uri-list] list of all prediction models get "/report/?" do - models = Model::Prediction.all + models = Model::Validation.all case @accept when "text/uri-list" uri_list = models.collect{|model| uri("/report/#{model.model_id}")} @@ -26,7 +26,7 @@ end get "/report/:id/?" do model = Model::Lazar.find params[:id] resource_not_found_error "Model with id: #{params[:id]} not found." unless model - prediction_model = Model::Prediction.find_by :model_id => params[:id] + prediction_model = Model::Validation.find_by :model_id => params[:id] validation_template = File.join(File.dirname(__FILE__),"../views/model_details.haml") if File.directory?("#{File.dirname(__FILE__)}/../../lazar") diff --git a/lib/swagger.rb b/lib/swagger.rb new file mode 100644 index 0000000..916439e --- /dev/null +++ b/lib/swagger.rb @@ -0,0 +1,8 @@ +set :public_folder, File.join("/home/ist/swagger-ui/dist/") +# route to swagger API file +get "/" do + response['Content-Type'] = "text/html" + index_file = File.join("/home/ist/swagger-ui/dist/index.html") + #bad_request_error "API Documentation in Swagger JSON is not implemented.", uri("/#{SERVICE}/api") unless File.exists?(index_file) + File.read(index_file) +end |