From 3869670b3acfb4de982f45ea24af940eccac5474 Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 18 Jun 2019 12:49:35 +0000 Subject: update routes and mime type and generate server uri for API file --- lib/api.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'lib/api.rb') 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 -- cgit v1.2.3