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)