Windows and http servers on ruby

Hi,
I wrote custom webrick servlet which parses *.html files with embedded
ruby code. It works fine on Linux, but on Windows it doesn’t work
properly
because pictures that are supposed to be on a web page do not show.

What can I do?

#!/usr/bin/ruby
require ‘webrick’
include WEBrick

class CustomServlet < HTTPServlet::AbstractServlet
def do_GET(req, resp)
unless defined?(ERB)
@logger.warn “#{self.class}: ERB not defined.”
raise HTTPStatus::Forbidden, “ERBHandler cannot work.”
end
#puts req.inspect
#puts “++++ #{req.request_uri} +++++++++++++++”
str=req.inspect
path=Dir.pwd+req.path
uri=req.request_uri.to_s
if File.stat(path).directory?
resp.body << “\nDirectory\n”
resp.body << “

Directory: #{req.path}


entries=Dir.entries(path)
resp.body << ‘Root directory’+"
\n"
entries[1…-1].each {|x|
resp.body << ‘
x=‘Parent Directory’ if x==’…’
resp.body << x << “

\n”
}
resp.body << “\n”
else
#puts ‘going to process file ‘+path
file=File.open(path).read #load normal file
if (path[-5…-1]==’.html’ or path[-4…-1]==’.htm’)
rhtml=ERB.new(file) #convert served string into code
#rhtml.run #run the code
file=rhtml.result #copy result to another string
resp.body << file
else
resp.body << file
end #if
end #if

end#def
end#class

def start_webrick(config = {})
config.update(:Port => 8080)
server = HTTPServer.new(config)
yield server if block_given?
[‘INT’, ‘TERM’].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end

start_webrick {|server|
server.mount(’/’,CustomServlet,"#{Dir.pwd}/proba")
}

I don’t know if this is your only issue, but there’s no “/” (root) on
Windows.
Try a drive letter (e.g. ‘c:’).

I also tried that, when i wrote own server based on httpserver class. I
thought it was the issue but it wasn’t, all i got was pc speaker
beeping.

Jacek P. wrote:

Hi,
I wrote custom webrick servlet which parses *.html files with embedded
ruby code. It works fine on Linux, but on Windows it doesn’t work properly
because pictures that are supposed to be on a web page do not show.

What can I do?

I don’t know if this is your only issue, but there’s no “/” (root) on
Windows.
Try a drive letter (e.g. ‘c:’).

Regards,

Dan