Ruby – Simple Web Server

Filed under ruby
Tagged as , , , , , , ,

Author: slac3dork
Site: http://snippet.c0de.me
Summary: Simple web server using Ruby’s standard library. Tested on Linux and Ruby 1.8.7.
Usage: ruby filename.rb

#!/usb/bin/ruby

#  _________      .__       .____   _______
# /   _____/ ____ |__|_____ |    |  \   _  \    ____
# \_____  \ /    \|  \____ \|    |  /  /_\  \  / ___\
# /        \   |  \  |  |_> >    |__\  \_/   \/ /_/  >
#/_______  /___|  /__|   __/|_______ \_____  /\___  /
#        \/     \/   |__|           \/     \//_____/
# http://snippet.c0de.me
# slac3dork[at]gmail[dot]com

require 'webrick'

# importing WEBrick module
include WEBrick

# Creating HTTPServer instance on port 2000
server = HTTPServer.new(
:Port => 2000,
:DocumentRoot => "/home/slac3dork/ruby/www/"
)

# To shutdown server if get an interrupt signal (ctrl-c).
trap("INT"){ server.shutdown }

# To run the server
server.start




ruby,code,code,snippet

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*