From b1254313f7485b97760b784a063d4a0473218277 Mon Sep 17 00:00:00 2001 From: _why Date: Thu, 6 Jul 2006 19:38:57 +0000 Subject: [PATCH] * lib/camping/fastcgi.rb: first stab at a FastCGI version of TheCampingServer. --- lib/camping/fastcgi.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/camping/fastcgi.rb b/lib/camping/fastcgi.rb index 685a7a7..4c1485d 100644 --- a/lib/camping/fastcgi.rb +++ b/lib/camping/fastcgi.rb @@ -7,6 +7,7 @@ # So where do you use the Camping::FastCGI class? Use it in your application's # postamble and then you can point your web server directly at your application. # See Camping::FastCGI docs for more. +require 'camping' require 'fcgi' module Camping @@ -89,6 +90,29 @@ def self.start(app) cf.start end + # Serve an entire directory of Camping apps. (See + # http://code.whytheluckystiff.net/camping/wiki/TheCampingServer.) + # + # Use this method inside your FastCGI dispatcher: + # + # #!/usr/local/bin/ruby + # require 'rubygems' + # require 'camping/fastcgi' + # Camping::Models::Base.establish_connection :adapter => 'sqlite3', :database => "/path/to/db" + # Camping::FastCGI.serve("/home/why/cvs/camping/examples") + # + def self.serve(path, index=nil) + require 'camping/reloader' + fast = Camping::FastCGI.new + fast.mount("/", index) if index + apps = Dir[File.join(path, '*.rb')].map do |script| + app = Camping::Reloader.new(script) + fast.mount("/#{app.mount}", app) + app + end + fast.start + end + private def match(path, mount)