summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2017-06-08 11:31:15 +0000
committergebele <gebele@in-silico.ch>2017-06-08 11:31:15 +0000
commit9335ef164b7a291cdee0bd23f9c1bf189cacd09b (patch)
treef701e414254c01841455990e18fef7d3e37fda47
parentdc6611684ac4bae65bcf18aae63bf895af8f157c (diff)
update for sinatra cors and swagger in one image
-rw-r--r--Gemfile4
-rw-r--r--api/api.json8
-rw-r--r--lazar-rest.gemspec3
-rw-r--r--lib/lazar-rest.rb28
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 }