John Doe
3/17/2006 11:16:00 PM
I'm trying to test Webrick by setting up a simple site under Windows. I run
a webrick .rb script from my U:/ drive which is my home directory. I'm
having trouble getting the documentroot set to the correct directory. And
regardless where I tell a file handler to be at (other than "/" such as
"/webrickFiles") it still just shows files in "/" (basically my home
directory). I've included the script below but note no matter what path I
set the third parameter in the s.mount("/files",...) call I get the same
aforementioned behavior. Also the "files/1.bmp" only gets loaded if 1.bmp is
at the root of my home directory. Can someone suggest to me how I can mount
the files servlet from U:\webrickFiles? Thanks.
----- example script below ---------------------
require 'webrick'
include WEBrick
s = HTTPServer.new
s.mount_proc("/") { | req, resp |
resp.body = '<img src="files/1.bmp"><p><ul><li><a href="block">Test
block</a></li><li><a href="files">Test files</a></li><li><a href="proc">Test
proc</a></li></ul>'
}
s.mount("/files",
HTTPServlet::FileHandler, "/",
true) #<= allow to show directory index.
s.mount_proc("/block") { | req, resp |
resp.body = "<hr><h1>a block mounted at </h1>#{req.script_name}"
}
myProc = Proc.new { | req, resp |
resp.body = "a proc mounted at #{req.script_name}"
}
s.mount_proc("/proc",myProc)
trap("INT"){ s.shutdown }
s.start