Powered by SmartDoc

WEBrick

WEBrick is a toolkit to builled web sesrver. To work CGIKit application with WEBrick, create an instance of the application and mount it as servlet.

Handlers for CGIKit are 3 types.

Handler Description
WEBrick::CGIKitServlet::PathHandler Handler that receives component path in the second argument.
WEBrick::CGIKitServlet::HashHandler Handler that receives a hash for accessors of CKApplication in the second argument.
WEBrick::CGIKitServlet::ApplicationHandler Handler that receives a CKApplication object in the second argument.

以下はApplicationHandlerを使った起動スクリプトです(付属サンプルのHelloWorldに添付してあります)。このスクリプトは、コンポーネントのパスとポート番号を指定して起動します。

A startup script using with ApplicationHandleris the following (attached in HelloWorld an example application). Specify component path and port number to run.

% webrick-app.rb ‘.’ 8080
# webrick-app.rb [component_path [port]]
require 'webrick'
require 'cgikit'

path = ARGV.shift || Dir.pwd
port = (ARGV.shift || 8080).to_i

app = CKApplication.new
app.component_path = path

server = WEBrick::HTTPServer.new({:Port => port})
server.mount('/', WEBrick::CGIKitServlet::ApplicationHandler, app)

trap("INT"){ server.shutdown }
server.start