require 'rubygems' require 'backports' require 'rack' require 'mongrel' class Mise def initialize(port) @port = port end def call(env) req = Rack::Request.new(env) if req.params.has_key?('start') # start the new server and tell the requester when it's running Thread.new { Runner.new(req.params['port']) } return [200, {"Content-Type" => "text/html"}, "New server started"] else html = <<-HTML Mise en abyme

served from an entity on port #{@port} | descend into the abyss

HTML return [200, {"Content-Type" => "text/html"}, html] end end end class Runner attr_accessor :port def initialize(port) @port = port warn "Server started on port #{@port}" Rack::Handler::Mongrel.run(Mise.new(@port), :Port => @port) end end puts "Use a browser to go to http://localhost:9292/" Runner.new(9292)