Changeset 2069

Show
Ignore:
Timestamp:
11/27/07 21:49:28 (11 months ago)
Author:
tokuhirom
Message:

lang/ruby/ssb:
- Dir.pwd やめて FILE みるようにしてどっから実行しても大丈夫なように
- bind address と port number をオプションで指定できるようにした
- File.join でポータビリティ確保。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/ruby/ssb/ssb-webrick.rb

    r1978 r2069  
    11require 'webrick' 
     2require 'optparse' 
    23 
    3 basedir = Dir.pwd 
    4 Dir.chdir "#{basedir}/public_html" 
     4port = 10080 
     5bind_address = '127.0.0.1' 
     6 
     7opt = OptionParser.new 
     8opt.on('-p port', '--port port') {|v| port = v.to_i } 
     9opt.on('--bind ip') {|v| bind_address = v } 
     10opt.parse!(ARGV) 
     11 
     12bindir = File.dirname(__FILE__) 
     13docroot = File.expand_path(File.join(bindir, 'public_html')) 
     14Dir.chdir(docroot) 
    515 
    616srv = WEBrick::HTTPServer.new({ 
    7     :DocumentRoot => "#{ Dir.pwd }", 
    8     :BindAddress => '127.0.0.1', 
    9     :Port => 10080, 
     17    :DocumentRoot => docroot, 
     18    :BindAddress => bind_address, 
     19    :Port => port, 
    1020}) 
    1121trap("INT"){ srv.shutdown } 
    12 srv.mount('/', WEBrick::HTTPServlet::CGIHandler, "#{ Dir.pwd }/index.rbx") 
     22p File.join(docroot, 'index.rbx') 
     23srv.mount('/', WEBrick::HTTPServlet::CGIHandler, File.join(docroot, 'index.rbx')) 
    1324%w(javascripts stylesheets emoji images).each {|x| 
    14     srv.mount("/#{x}/", WEBrick::HTTPServlet::FileHandler, "#{ Dir.pwd }/#{x}/") 
     25    srv.mount("/#{x}/", WEBrick::HTTPServlet::FileHandler, File.join(docroot, x)) 
    1526} 
    1627srv.start