Skip to content

Instantly share code, notes, and snippets.

@sousk
Created June 16, 2009 00:33
Show Gist options
  • Save sousk/130450 to your computer and use it in GitHub Desktop.
Save sousk/130450 to your computer and use it in GitHub Desktop.
weby: make current directory accessible via HTTP
#!/usr/bin/env ruby
require 'webrick'
require 'optparse'
include WEBrick
OPTIONS = {
# :BindingAddress => '0.0.0.0',
:Port => 3000,
:Charset => 'UTF-8',
:DocumentRoot => Dir.getwd,
}
ARGV.options do |opts|
script_name = File.basename($0)
opts.separator ""
opts.on("-p", "--port=port", Integer, "port number") {|v|
OPTIONS[:Port] = v
}
opts.on("-b", "--bind=binding-address", String, "binding address") {|v|
OPTIONS[:BindingAddress] = v
}
opts.parse!
end
s = HTTPServer.new(OPTIONS)
trap("INT"){
s.shutdown
}
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment