From: Eko Budi Setiyo Date: 2005-03-07T13:13:44+09:00 Subject: Re: WEBrick for a local application? vruz wrote: >>Actually, I believe in the single point of entry power. >>I used it in FuseLogic(php) and QLogic (ruby). index.php or index.rb >>will decide which module will be executed base on the user response >>(REQUES_URI). >>One example of the benefit among the others is, lets say I change my >>hosting company and some how the install ruby on difference path. What I >>have to do is just change >>the first line from #!/bin/ruby to #!/user/bin/ruby (this is example >>only!) in the index.rb >>The reason I ask is I already try to use Webrick and doesn't do what I >>want. >>What happen to my scripts is, lets say I already use my browser to hit >>http://127.0.0.1/index.rb/init/version than after that I hit >>http://127.0.0.1/index.rb/bittorrents/main , >>Webrick will always give the same result as >>http://127.0.0.1/index.rb/init/version >> >>I really want to use webrick also for my RubyToday project >> >>May be I am doing some thing wrong here. I don't know >> >>Regards >>Eko >> >> > > >Jeremy, the confusion arises because Eko is asking about a completely >different , unrelated, problem in this thread. > >Eko, maybe if you post some source code to look at ? > >That will make it way much easier to find what's your your problem about > >cheers, > vruz > > > > > Ok, here is my code #----------------------------------------------------------------- # #File Name = class.index.rb # # class Index < HTTPServlet::AbstractServlet def do_GET(req,resp) temp = req.unparsed_uri.to_s temp = temp.str_ireplace('/index.rb/','') temp = 'fuse='+temp ARGV[0] = temp load('coreLoader.rb') resp.body = $Layout end def Index.get_instance config, *options load __FILE__ load('coreLoader.rb') Index.new config, *options end end #---------------------------------------------------------------------- # #file name = start_webrick.rb # require 'webrick' class String def str_replace(what,with) re = Regexp.new(Regexp.quote(what)) self.gsub(re,with) end def str_ireplace(what,with) re = Regexp.new(Regexp.quote(what), Regexp::IGNORECASE) self.gsub(re,with) end end $Layout = '' def puts(string = '') $Layout += "\n"+string.to_s super end include WEBrick load('class.index.rb') def start_webrick(config = {}) ##config.update(:Port => 8080) config.update(:Port => 80) config.update(:DirectoryIndex => 'a.rb') $server = HTTPServer.new(config) yield server if block_given? ['INT','TERM'].each { |signal| trap(signal) {server.shutdown} } $server.mount('/index',Index) $server.start end start_webrick(:DocumentRoot => File.dirname(__FILE__)) regards Eko