Skip to content

Instantly share code, notes, and snippets.

@niw
Created October 29, 2013 03:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niw/7208705 to your computer and use it in GitHub Desktop.
Save niw/7208705 to your computer and use it in GitHub Desktop.
Running rubygems server on localhost.
#!/usr/bin/env ruby
require 'webrick'
require 'rubygems'
require 'rubygems/gem_runner'
require 'rubygems/exceptions'
REPOSITORY_ROOT = File.expand_path("../", __FILE__)
# Update index
begin
Gem::GemRunner.new.run ["generate_index", "-d", REPOSITORY_ROOT]
rescue Gem::SystemExitException => e
exit e.exit_code
end
# Start HTTP server
WEBrick::HTTPServer.new(
:Port => 3000,
:BindAddress => '127.0.0.0',
:DocumentRoot => REPOSITORY_ROOT,
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes
).tap do |server|
trap('INT') do
server.shutdown
end
server.start
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment