Skip to content

Instantly share code, notes, and snippets.

@lwe
Created August 18, 2011 14:32
Show Gist options
  • Save lwe/1154170 to your computer and use it in GitHub Desktop.
Save lwe/1154170 to your computer and use it in GitHub Desktop.
Start a simple HTTP server to serve current directory.
#!/usr/bin/ruby -w
require 'rubygems'
require 'optparse'
require 'rack'
# setup options
options = { :Port => 4000, :Host => "0.0.0.0" }
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: serveme [-p PORT] [-h HOST] [-s thin|webrick|...]"
opts.separator ""
opts.on("-p", "--port PORT", "run on port (default: 4000)") { |p| options[:Port] = p.to_i }
opts.on("-h", "--host HOST", "listen on host (default: 0.0.0.0)") { |h| options[:Host] = h }
opts.on("-s", "--server SERVER", "use server (thin, webrick, mongrel..)") { |s| options[:server] = s }
opts.on_tail("-?", "--help", "Show this message") { puts opts; exit }
end
# parse options
begin
opt_parser.parse! ARGV
rescue OptionParser::InvalidOption => e
warn e.message
abort opt_parser.to_s
end
# start rack server
options[:app] = Rack::Directory.new Dir.pwd
srv = Rack::Server.new(options).start
@lwe
Copy link
Author

lwe commented Aug 18, 2011

Installation:

  1. curl https://raw.github.com/gist/1154170/6aeb61dfac060fe1ad7aaca9640c3051029ed571/serveme > /usr/local/bin/serveme
  2. chmod +x /usr/local/bin/serveme
  3. change into directory to serve via http
  4. serveme

Type serveme --help for help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment