Question

I must be missing something from Rack's non-existant docs :) I'm trying to add additional webservice routes to ruhoh, and can get them to work at localhost:9292/test, but the new Rack::Builder object seems to override the last, as I can no longer access the default blog at localhost:9292/. I've tried different ways of defining the new routes without declaring Rack::Builder.new, but can't get anything to work.

What is the best way to add additional routes using this interface?

require 'rack'
require 'ruhoh'

run Ruhoh::Program.preview

# Additional routes

builder = Rack::Builder.new do
  use Rack::CommonLogger
  map '/test' do
    run Proc.new {|env| [200, {"Content-Type" => "text/html"},  StringIO.new("infinity 0.1")] }
  end
end

run builder
Was it helpful?

Solution

In the way you use it, run Ruhoh::Program.preview will never serve requests.

You should put it into builder:

builder = Rack::Builder.new do
  use Rack::CommonLogger
  map '/' do
    run Ruhoh::Program.preview
  end

  map '/test' do
    run Proc.new {|env| [200, {"Content-Type" => "text/html"},  StringIO.new("infinity 0.1")] }
  end
end

run builder
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top