diff options
-rw-r--r-- | api/api.json | 4 | ||||
-rw-r--r-- | application.rb | 13 | ||||
-rw-r--r-- | config.ru | 2 | ||||
-rw-r--r-- | lib/api.rb | 22 | ||||
-rw-r--r-- | views/layout.haml | 2 | ||||
-rw-r--r-- | views/predict.haml | 2 |
6 files changed, 27 insertions, 18 deletions
diff --git a/api/api.json b/api/api.json index 194b0d8..6d42127 100644 --- a/api/api.json +++ b/api/api.json @@ -2,7 +2,7 @@ "openapi": "3.0.0", "servers": [ { - "url": "https://lazar.in-silico.ch/api" + "url": "https://SERVER_URI/api" } ], "info": { @@ -24,7 +24,7 @@ "url": "https://github.com/OpenRiskNet/home/blob/master/openshift/deployments/lazar/README.md" }, "paths": { - "/api": { + "/api.json": { "get": { "tags": [ "api" diff --git a/application.rb b/application.rb index a2ec091..87d676b 100644 --- a/application.rb +++ b/application.rb @@ -51,11 +51,14 @@ before do "substance", "swagger", "validation"] - if request.path.split("/")[1] == "api" || $paths.include?(request.path.split("/")[2]) + if request.path =~ /predict/ @accept = request.env['HTTP_ACCEPT'].split(",").first response['Content-Type'] = @accept - else + halt 400, "Mime type #{@accept} is not supported." unless @accept == "text/html" || "*/*" @version = File.read("VERSION").chomp + else + @accept = request.env['HTTP_ACCEPT'].split(",").first + response['Content-Type'] = @accept end end @@ -253,7 +256,7 @@ get '/prediction/:neighbor/details/?' do haml :details, :layout => false end -get '/license' do +get '/predict/license' do @license = RDiscount.new(File.read("LICENSE.md")).to_html haml :license, :layout => false end @@ -263,7 +266,7 @@ get '/predict/faq' do haml :faq#, :layout => false end -get '/help' do +get '/predict/help' do haml :help end @@ -273,7 +276,7 @@ get '/style.css' do end # for swagger representation -get '/swagger-ui.css' do +get '/api/swagger-ui.css' do headers 'Content-Type' => 'text/css; charset=utf-8' scss :style end @@ -1,4 +1,4 @@ -ENV["BATCH_MODE"] = "false" +ENV["BATCH_MODE"] = "true" ENV["LAZAR_ENV"] = "production" require 'bundler' Bundler.require @@ -1,23 +1,29 @@ get "/api" do api_file = File.join("api", "api.json") + `sed -i 's/SERVER_URI/#{request.env['HTTP_HOST']}/' #{api_file}` halt 400, "API Documentation in Swagger JSON is not implemented." unless File.exists?(api_file) case @accept when "text/html" response['Content-Type'] = "text/html" index_file = File.join(ENV['HOME'],"swagger-ui/dist/index.html") - File.read(index_file) + return File.read(index_file) when "application/json" - response['Content-Type'] = "application/json" - api_hash = JSON.parse(File.read(api_file)) - api_hash["host"] = request.env['HTTP_HOST'] - return api_hash.to_json + redirect("/api/api.json") else halt 400, "unknown MIME type '#{@accept}'" end end get "/api/api.json" do - response['Content-Type'] = "text/html" - index_file = File.join(ENV['HOME'],"swagger-ui/dist/index.html") - File.read(index_file) + api_file = File.join("api", "api.json") + `sed -i 's/SERVER_URI/#{request.env['HTTP_HOST']}/' #{api_file}` + case @accept + when "text/html" + response['Content-Type'] = "application/json" + return File.read(api_file) + when "application/json" + return File.read(api_file) + else + halt 400, "unknown MIME type '#{@accept}'" + end end diff --git a/views/layout.haml b/views/layout.haml index 3304c69..f06a700 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -65,7 +65,7 @@ © %a{:href => 'http://www.in-silico.ch', :rel => "external"} <i style="font-family: serife">in silico</i> toxicology gmbh 2004 - #{Time.now.year.to_s} | - %a{:href => to("/license"), :rel => "external"} GPL3 License + %a{:href => to("/predict/license"), :rel => "external"} GPL3 License %supporters.row %div.card-body.text-center %div.card-title diff --git a/views/predict.haml b/views/predict.haml index d525b33..7602915 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -169,7 +169,7 @@ %br %span.btn.btn-file{:style=>"background-color:white;"} %input.form-control-file{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>"text/csv"} - %a.btn.btn-warning{:href => to("/help"), :rel => "external", :style=>"margin-left: 1em;"} Help + %a.btn.btn-warning{:href => to("/predict/help"), :rel => "external", :style=>"margin-left: 1em;"} Help %fieldset#middle.card.bg-light #models.card-body |