summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2019-06-18 12:49:35 +0000
committergebele <gebele@in-silico.ch>2019-06-18 12:49:35 +0000
commit3869670b3acfb4de982f45ea24af940eccac5474 (patch)
tree6ad877b04260b252cd6af06014741cbd59928e56 /lib
parent091e0c3d84223bb7513c88cbac103d0aaee1a32c (diff)
update routes and mime type and generate server uri for API file
Diffstat (limited to 'lib')
-rw-r--r--lib/api.rb22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/api.rb b/lib/api.rb
index c3b27ce..dffa9d7 100644
--- a/lib/api.rb
+++ b/lib/api.rb
@@ -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