Created
August 19, 2012 17:20
-
-
Save dvliman/3396439 to your computer and use it in GitHub Desktop.
file:// to http://. simple http server on your root directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# thanks to jim weirich | |
# run ./servefiles from the root directory | |
require 'webrick' | |
include WEBrick | |
dir = Dir::pwd | |
port = (ARGV.first || (12000 + (dir.hash % 1000))).to_i | |
url = "http://#{Socket.gethostname}:#{port}" | |
puts "Opening #{url}" | |
`open #{url}` | |
s = HTTPServer.new( | |
:Port => port, | |
:DocumentRoot => dir | |
) | |
trap("INT"){ s.shutdown } | |
s.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment