summaryrefslogtreecommitdiff
path: root/lib/lazar-rest.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lazar-rest.rb')
-rw-r--r--lib/lazar-rest.rb41
1 files changed, 22 insertions, 19 deletions
diff --git a/lib/lazar-rest.rb b/lib/lazar-rest.rb
index 41010e1..4fd806c 100644
--- a/lib/lazar-rest.rb
+++ b/lib/lazar-rest.rb
@@ -3,15 +3,19 @@ require "sinatra/reloader"
require 'sinatra/cross_origin'
configure do
- enable :reloader if development?
+ enable :reloader #if development?
enable :cross_origin
+ disable :show_exceptions
+ disable :raise_errors
end
#set :protection, :except => :frame_options
# Environment setup from unicorn -E param
ENV["LAZAR_ENV"] = ENV["RACK_ENV"]
-
+require "../lazar/lib/lazar.rb"
+require "../qsar-report/lib/qsar-report.rb"
+=begin
if ENV["LAZAR_ENV"] == "development"
require "../lazar/lib/lazar.rb"
require "../qsar-report/lib/qsar-report.rb"
@@ -19,28 +23,28 @@ else
require "lazar"
require "qsar-report"
end
+=end
include OpenTox
-#require 'rack/cors'
-
-set :show_exceptions => false
-=begin
-# add CORS support for swagger
- config.allow do |allow|
- allow.origins '*'
- allow.resource "/#{SERVICE}/*",
- :methods => [:head, :get, :post, :put, :delete, :options],
- :headers => :any,
- :max_age => 0
- end
-end
-=end
before do
- @accept = request.env['HTTP_ACCEPT'].split.last
+ @accept = request.env['HTTP_ACCEPT']
response['Content-Type'] = @accept
end
+not_found do
+ 400
+ "Path '#{request.env["REQUEST_PATH"]}' not found.\n"
+end
+
+error do
+ response['Content-Type'] = "text/plain"
+ error = request.env['sinatra.error']
+ body = error.message+"\n"
+ error.respond_to?(:http_code) ? code = error.http_code : code = 500
+ halt code, body
+end
+
# https://github.com/britg/sinatra-cross_origin#responding-to-options
options "*" do
response.headers["Allow"] = "HEAD,GET,PUT,POST,DELETE,OPTIONS"
@@ -48,8 +52,6 @@ options "*" do
200
end
-
-
[
"aa.rb",
"api.rb",
@@ -63,3 +65,4 @@ end
"swagger.rb",
"validation.rb"
].each{ |f| require_relative f }
+