This post originated from an RSS feed registered with Ruby Buzz
by Andrew Montgomery.
Original Post: Static site development
Feed Title: Dark Liquid - Ruby
Feed URL: http://feeds.feedburner.com/DarkLiquid-Ruby
Feed Description: Ruby and Rails related ramblings by Andrew Montgomery
When developing a static site, or editing an existing one, its a bitch to try and remember things like relative and absolute paths, etc etc. I didn���t want to have to mess with that and I certainly didn���t want the hassle of setting up apache or lighty just to serve files from the directory I had mirrored the site.
So, Ruby to the rescue! 2 minutes later and I had this serving my files for me:
#!/usr/local/bin/ruby
require 'webrick'
include WEBrick
def webserve(port, directory)
server = HTTPServer.new(
:Port => port,
:DocumentRoot => directory
)
trap("INT"){ server.shutdown }
server.start
end
port = ARGV[0] || 3000
directory = ARGV[1] || Dir::pwd
webserve(port, directory)
Just run it in the directory that has your files in, or call it like:
webserver 3000 /path/to/my/files
and voila, instant server.
I don���t know how people live without this stuff.