2009-11-24 59 views
0

我寫過一些ruby CGI腳本(使用Ruby CGI類),使用lighttpd從我的生產服務器提供服務。我想用我的開發服務器測試它們。基本上,我想把我所有的CGI腳本放在一個目錄中,並在那個目錄中啓動。然後,對http://localhost:3000/<script>的任何請求應在當前目錄中執行< script>並返回結果。如果瘦客戶端有內置的方式,我無法找到它。如果你知道你在做什麼,我會想象這個Rack配置文件很容易,但我不知道。如何在CGI腳本中使用ruby thin?

更新:

此rackup文件似乎工作。我不確定這是否是最好的解決方案,但它對開發環境應該沒問題。

run(lambda do |env| 
    require 'rubygems' 
    require 'systemu' 
    script = env['REQUEST_PATH'][1..-1] + '.rb' 
    response = '' 
    err = '' 
    systemu(['ruby', script], 'stdout' => response, 'stderr' => err, 'env' => { 
    'foo' => 'bar' }) 
    if err.length > 0 
    [ 500, {'Content-Type' => 'text/plain'}, err ] 
    else 
    idx = 0 
    status = -1 
    headers = {} 
    while true 
     line_end = response.index("\n", idx) 
     line = response[idx..line_end].strip 
     idx = line_end+1 

     if status < 0 
     if line =~ /(\d\d\d)/ 
      status = $1.to_i 
     else 
      raise "Invalid status line: #{line}" 
     end 
     elsif line.empty? 
     break 
     else 
     name, value = line.split /: ?/ 
     headers[name] = value 
     end 
    end 
    content = response[idx..-1] 
    [status, headers, content] 
    end 
end) 

回答

0

我有點不清楚爲什麼Rack是必要的。如果您使用Ruby內置的CGI模塊編寫腳本,則應該能夠將瘦目錄作爲cgi-bin來處理,就像Apache ScriptAlias directive一樣,Ruby CGI將負責處理剩下的內容。如果瘦不能做到這一點,也許lighttpd會是一個更好的解決方案。