summaryrefslogtreecommitdiff
path: root/lib/api.rb
blob: dffa9d7ab1bfb9b222c2dfb6fe58e43e323fce79 (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
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")
    return File.read(index_file)
  when "application/json"
    redirect("/api/api.json")
  else
    halt 400, "unknown MIME type '#{@accept}'"
  end
end

get "/api/api.json" do
  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