Apache使うよりぜんぜん手軽だなー。
でも、ERBHandlerの使い方、あってるのかな?
#!/usr/bin/env ruby
require "webrick"
include WEBrickclass MyERBHandler < HTTPServlet::ERBHandler
ERB = "/usr/local/ruby/bin/erb.bat"def initialize(server, filename)
super
@filename = filename
enddef do_GET(req, res)
IO.popen("#{ERB} #{@filename}") {|io|
res.body = io.read
}
res["content-type"] = "text/html"
end
endHTTPServlet::FileHandler.add_handler("rhtml", MyERBHandler)
s = WEBrick::HTTPServer.new(:Port=>8000)
s.mount("/myeruby", HTTPServlet::FileHandler, Dir.pwd)
trap("INT") {s.shutdown}
s.start
<html>
<head>
<title>hello, WEBrick+ERb</title>
</head>
<body>
現在時刻: <%= Time.now %>
</body>
</html>