views:

42

answers:

1

Is there an easy way to fire up a web browser for a folder?

eg.

I am in a folder that contains a website (index.html and other files) and I want to browse the site through a browser. Is there a gem that I just launch to make this folder browsable?

In this way I don't have to install nginx just for a specific folder. And when you install nginx you have to bother with configuration files and so on.

Kinda how Rails does it with:

rails server
+5  A: 

Yes, there is... Throw the following in a file called webserver:

#!/usr/bin/env ruby
require 'webrick'
include WEBrick

server = HTTPServer.new(:Port => 3000, :DocumentRoot => Dir::pwd)

trap("INT"){ server.shutdown }
server.start

Then, perform the following (This assumes Mac OSX):

$ sudo chmod 755 webserver
$ sudo chown root:wheel webserver
$ sudo cp webserver /usr/local/bin/webserver (or somewhere in your path)

Now, just run webserver from the directory you want to use as the document root. A webserver will now be running on localhost:3000.

Hope this helps!

UPDATE

I just remembered after reading a post on Phusion Passenger 3.0 progress that there will be a passenger lite option...

Brian
I see a lot of these solutions with Webrick. Is this possible with Mongrel and Thin too? Why do they all use Webrick?
never_had_a_name
I'm pretty certain it is just as easy to do w/ mongrel or thin. I believe that most examples use WEBrick because it is included with the Ruby distribution. Honestly, for simple tasks, WEBrick is probably sufficient.
Brian