Wish list: webrick server with cgi test file

Anyone has a webrick server which works with a cgi test file, to share
with me?
Hopefully, not all webrick users are at the rails conference!

I have tried various combinations with various errors. Here is the
latest attempt
using the info on this page for server and test file
http://microjet.ath.cx/webrickguide/html/CGIHandler.html
----------------->
require ‘webrick’

include WEBrick # let’s import the namespace so
# I don’t have to keep typing
# WEBrick:: in this documentation.

def start_webrick(config = {})

always listen on port 8080

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|
cgi_dir = ‘/library/webserver/documents/ruby/cgi-bin’
server.mount(’/cgi-bin’, HTTPServlet::FileHandler, cgi_dir,
{:FancyIndexing=>true})
}

with the test file in cgi-bin, test2.cgi, executable
#!/usr/bin/env ruby
print “Content-type: text/plain\r\n\r\n”
ENV.keys.sort.each{|k| puts “#{k} ==> #{ENV[k]}”}

I get an error message.
env: ruby: No such file or directory
With other attempts I get other errors.

I started with the webserver on this page
http://microjet.ath.cx/webrickguide/html/What_is_WEBrick.html
---------------->
require ‘webrick’

include WEBrick # let’s import the namespace so
# I don’t have to keep typing
# WEBrick:: in this documentation.

def start_webrick(config = {})

always listen on port 8080

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(:DocumentRoot =>
‘/library/webserver/documents/ruby/cgi-bin’)

it serves a hello.html file in cgi-bin directory fine.
----------------->

A Small Hello

Hi

This is very minimal "hello world" HTML document.

anne001 wrote:

I get an error message.
env: ruby: No such file or directory
With other attempts I get other errors.

This particular error has nothing to do with webrick. What is happening
is that the /usr/bin/env command cannot find ruby in it’s path. The
first thing to try would be to replace

#!/usr/bin/env ruby

With

#!/usr/bin/ruby

Or where ever your ruby image is (try ‘which ruby’ to find out).

Thank you, changing that line did fix this example.
And with this line my other test cgi script works too. Thank you!!!

start_webrick(:DocumentRoot => ‘/var/www’)

is functionally similar to:

start_webrick {|server|
doc_root = =’/var/www’
server.mount("/" HTTPServlet::FileHandler doc_root,
{:FancyIndexing=>true})
}

What is a webrick servlet?
http://microjet.ath.cx/webrickguide/html/CGIHandler.html

I can serve my cgi test file with a webrick server with or without
servermount…
why does this page seem to say cgi needs a cgi handler?
Are the two servers different?

first server
--------------->
require ‘webrick’

include WEBrick # let’s import the namespace so
# I don’t have to keep typing
# WEBrick:: in this documentation.

def start_webrick(config = {})

always listen on port 8080

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(:DocumentRoot =>
‘/library/webserver/documents/ruby/cgi-bin’)

second server
------------------>
require ‘webrick’

include WEBrick # let’s import the namespace so
# I don’t have to keep typing
# WEBrick:: in this documentation.

def start_webrick(config = {})

always listen on port 8080

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|
cgi_dir = ‘/library/webserver/documents/ruby/cgi-bin’
server.mount(’/cgi-bin’, HTTPServlet::FileHandler, cgi_dir,
{:FancyIndexing=>true})
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs