Skip to content

Instantly share code, notes, and snippets.

Created September 29, 2013 09:10
Show Gist options
  • Save anonymous/6750730 to your computer and use it in GitHub Desktop.
Save anonymous/6750730 to your computer and use it in GitHub Desktop.
どどんとふ on Rack ・・・とはいえCGIをRackから呼び出してるだけ。 ソースコードの各所を実行したい環境に合わせて変更してください。
# coding: utf-8
require 'open3'
Encoding.default_external = 'UTF-8'
class CgiApplication
def call(env)
e = Hash.new
env.each {|key, value|
v = String.try_convert value
unless v.nil?
e[key] = v
end
}
# Windows版Ruby 2.0.0-x64 で動作確認
# DodontoF_Websetを同じディレクトリに置いているものとします
Open3.popen3(e, "C:\\Ruby200-x64\\bin\\ruby.exe", "DodontoFServer.rb", {:chdir => "./DodontoF_WebSet/public_html/DodontoF/", :unsetenv_others => true}) {|i, o, e, t|
i.write env['rack.input'].read
i.close
p e.read
response = Rack::Response.new do |r|
r.status = 200
o.each { |line|
if line.strip.empty?
break
end
s = line.split(":", 2).each { |s| s.strip }
if s[0] == 'status'
r.status = s[1]
else
r[s[0]] = s[1]
end
}
r.write o.read
end
response.finish
}
end
e
# coding: utf-8
require './cgi_application.rb'
map '/DodontoF/DodontoFServer.rb' do
run CgiApplication.new
end
run Rack::Directory.new('./DodontoF_WebSet/public_html')
source 'https://rubygems.org'
gem 'rack', '~>1.1'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment