Skip to content

Commit

Permalink
- Add pretty-printing. Doesn't actually work all that well.
Browse files Browse the repository at this point in the history
  • Loading branch information
jordansissel committed Apr 9, 2011
1 parent 74aad9d commit 1a1a3c6
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions lib/logstash/web/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LogStash::Web::Server < Sinatra::Base
set :views, "#{File.dirname(__FILE__)}/views"

use Rack::CommonLogger
#use Rack::ShowExceptions
use Rack::ShowExceptions

def initialize(settings={})
super
Expand Down Expand Up @@ -154,11 +154,7 @@ def api_search
when "json"
headers({"Content-Type" => "text/plain" })
# TODO(sissel): issue/30 - needs refactoring here.
if @results.error?
body({ "error" => @results.error_message }.to_json)
else
body @results.to_json
end
body({ "error" => @results.error_message }.to_json)
end # case params[:format]
next
end
Expand Down Expand Up @@ -212,10 +208,13 @@ def api_search
body erb :"search/results.txt", :layout => false
when "json"
headers({"Content-Type" => "text/plain" })
# TODO(sissel): issue/30 - needs refactoring here.
response = @results
p response.to_hash
body response.to_json
pretty = params.has_key?("pretty")
if pretty
#ap :fields => @results.events.first.fields
body JSON.pretty_generate(@results.to_hash)
else
body @results.to_json
end
end # case params[:format]
end # @backend.search
end # def api_search
Expand Down Expand Up @@ -319,7 +318,7 @@ def api_search

#Rack::Handler::Thin.run(
Mizuno::HttpServer.run(
Rack::CommonLogger.new( \
Rack::ShowExceptions.new( \
LogStash::Web::Server.new(settings))),
#Rack::CommonLogger.new( \
#Rack::ShowExceptions.new( \
LogStash::Web::Server.new(settings),
:Port => settings.port, :Host => settings.address)

0 comments on commit 1a1a3c6

Please sign in to comment.