Module: Rack::Handler::Agoo
- Defined in:
- lib/rack/handler/agoo.rb
Overview
The Rack::Handler::Agoo module is a handler for common rack config.rb files.
Class Method Summary collapse
-
.run(handler, options = {}) ⇒ Object
Run the server.
Class Method Details
.run(handler, options = {}) ⇒ Object
Run the server. Options are the same as for Agoo::Server plus a :prot and :root option.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rack/handler/agoo.rb', line 12 def self.run(handler, ={}) port = 9292 root = '.' default_handler = nil not_found_handler = nil path_map = {} default_handler = handler unless handler.nil? .each { |k,v| if :port == k port = v.to_i .delete(k) elsif :root == k root = v .delete(k) elsif k.is_a?(String) && k.start_with?('/') path_map[k] = v .delete(k) elsif k.nil? not_found_handler = v .delete(k) end } [:thread_count] = 0 server = ::Agoo::Server.new(port, root, ) path_map.each { |path,handler| server.handle(nil, path, handler) } unless default_handler.nil? server.handle(nil, '/', default_handler) server.handle(nil, '/**', default_handler) end server.handle_not_found(not_found_handler) unless not_found_handler.nil? server.start end |