diff options
author | gebele <gebele@in-silico.ch> | 2019-06-18 12:49:35 +0000 |
---|---|---|
committer | gebele <gebele@in-silico.ch> | 2019-06-18 12:49:35 +0000 |
commit | 3869670b3acfb4de982f45ea24af940eccac5474 (patch) | |
tree | 6ad877b04260b252cd6af06014741cbd59928e56 /lib/api.rb | |
parent | 091e0c3d84223bb7513c88cbac103d0aaee1a32c (diff) |
update routes and mime type and generate server uri for API file
Diffstat (limited to 'lib/api.rb')
-rw-r--r-- | lib/api.rb | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -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 |