We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

ishikawa on 08/01/06


Tagged

server ruby


Versions (?)


Simple webrick server


Published in: Ruby 


Simple HTTP server daemon (webrick).

  1. #!/usr/bin/ruby
  2.  
  3. require 'webrick'
  4. include WEBrick
  5.  
  6. def start_webrick(config = {})
  7. config.update(:Port => 5001)
  8. server = HTTPServer.new(config)
  9.  
  10. yield server if block_given?
  11. ['INT', 'TERM'].each do |signal|
  12. trap(signal) { server.shutdown }
  13. end
  14.  
  15. server.start
  16. end
  17.  
  18. start_webrick(:DocumentRoot => 'path-to-document-root',
  19. :ServerType => Daemon)

Report this snippet 

You need to login to post a comment.