WEBrick default index page

M

mitchell

Instead of using an index.html, index.rhtml, index.cgi, etc. as the
default page to load on localhost:[port], I was wondering if it was
possible to load a servlet instead (i.e. '/index'). I have looked at
the WEBrick source, but could not figure out how to do this (even like
trying to execute a request or response).

Any help would be greatly appreciated.
 
G

Ghislain Mary

Hi,

mitchell a écrit :
Instead of using an index.html, index.rhtml, index.cgi, etc. as the
default page to load on localhost:[port], I was wondering if it was
possible to load a servlet instead (i.e. '/index'). I have looked at
the WEBrick source, but could not figure out how to do this (even like
trying to execute a request or response).

Any help would be greatly appreciated.

I am not sure I really understood what you want to do but I think you
can do something like:

require 'webrick'

svr = WEBrick::HTTPServer.new(
:port => 8080,
:BindAddress => 'localhost'
)

svr.mount_proc('/') { |req, res|
res.body = "This is not the default index!"
res['content-type'] = "text/plain"
}

trap("INT") { svr.shutdown }

svr.start


Or you can mount a servlet instead of a proc...

HTH

Ghislain
 
M

mitchell

Thank you, that worked. I do remember trying that earlier, but
something else had broken so I forgot about it.
 

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

No members online now.

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top