From 9335ef164b7a291cdee0bd23f9c1bf189cacd09b Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 8 Jun 2017 11:31:15 +0000 Subject: update for sinatra cors and swagger in one image --- Gemfile | 4 +++- api/api.json | 8 ++++---- lazar-rest.gemspec | 3 ++- lib/lazar-rest.rb | 28 +++++++++++++++++++++++----- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index 04af6bd..d53900b 100644 --- a/Gemfile +++ b/Gemfile @@ -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/api/api.json b/api/api.json index cf77f78..c226c90 100644 --- a/api/api.json +++ b/api/api.json @@ -2,19 +2,19 @@ "swagger": "2.0", "info": { "description": "REST API webservice for lazar and nano-lazar. \n*lazar* (lazy structure–activity relationships) is a modular framework for predictive toxicology. With activated Authentication & Authorization, subjectid authorization token are obligatory for designated services.\n", - "version": "1.0.0", + "version": "1.1.0", "title": "Lazar & Nano-Lazar REST Service", "contact": { "name": "in silico toxicology gmbh", "email": "service@in-silico.ch", - "url": "www.in-silico.ch" + "url": "https://in-silico.ch" }, "license": { "name": "GNU GENERAL PUBLIC LICENSE", "url": "https://github.com/opentox/lazar-rest/blob/master/LICENSE" } }, - "host": "enm.in-silico.ch", + "host": "api.in-silico.ch", "externalDocs": { "description": "See also *lazar-rest* documentation on Github\n", "url": "https://github.com/opentox/lazar-rest" @@ -1212,4 +1212,4 @@ "description": "Nanoparticle" } ] -} \ No newline at end of file +} 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 } -- cgit v1.2.3