Simple webrick server


/ Published in: Ruby
Save to your folder(s)

Simple HTTP server daemon (webrick).


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.