Webrick question

D

DeZo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top