summaryrefslogtreecommitdiff
path: root/lib/lazar-rest.rb
blob: 41010e116d7f701ccada5f1c6d1c8d06ca72a152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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"]

if ENV["LAZAR_ENV"] == "development"
  require "../lazar/lib/lazar.rb"
  require "../qsar-report/lib/qsar-report.rb"
else
  require "lazar"
  require "qsar-report"
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
  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",
  "compound.rb",
  "dataset.rb",
  "feature.rb",
  "model.rb",
  "nanoparticle.rb",
  "report.rb",
  "substance.rb",
  "swagger.rb",
  "validation.rb"
].each{ |f| require_relative f }