From: Jan Svitok Date: 2006-09-21T02:59:19+09:00 Subject: Re: super simple serving of ruby pages On 9/20/06, zerohalo wrote: > Thanks, Jan. That was easy. Now .rhtml files render correctly. > > Is there a way to tell it to execute .rb files rather than treat them > as simple text files? > > Jan Svitok wrote: > > On 9/20/06, zerohalo wrote: > > > Yes, I tried that. Unfortunately there is no documentation on the > > > webrick site on how to use ERBHandler. I have this in a ruby script > > > which does start up the Webrick server. However, while it serves HTML > > > files fine, it treats RHTML files as binaries and RB files as just > > > plain text. Here's my code: > > > > require 'webrick' > > include WEBrick + module WEBrick + module HTTPServlet + FileHandler.add_handler("rb", CGIHandler) + end + end > > > > def start_webrick(config = {}) > > config.update(:Port => 8080) > > + config.update(:MimeTypes => {'rhtml' => 'text/html'}) > > server = HTTPServer.new(config) > > yield server if block_given? > > ['INT', 'TERM'].each {|signal| > > trap(signal) {server.shutdown} > > } > > - ruby_dir = File.expand_path('/data/sandbox/ruby') > > - server.mount("/data/sandbox/ruby", HTTPServlet::ERBHandler, ruby_dir) > > server.start > > end > > > > start_webrick(:DocumentRoot => '/data/sandbox/ruby') Now it starts .rb for me, although I'm not able to write any good cgi right now ;-) maybe it's because I'm on windows...