Skip to content

Commit

Permalink
* lib/camping/fastcgi.rb: new FastCGI app mounter for running severa…
Browse files Browse the repository at this point in the history
…l apps in a single process.
  • Loading branch information
_why committed May 18, 2006
1 parent 3302af5 commit a81c8a0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
= 1.4.2
=== 10th May, 2006
=== 18th May, 2006

* Efficient file uploads for multipart/form-data POSTs.
* Camping tool now uses Mongrel, if available. If not, sticks with WEBrick.
* Multiple apps can be loaded with the camping tool, each mounted according to their file name.

= 1.4.1
=== 3rd May, 2006
Expand Down
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ If you run them from the commandline, you'll probably just see a pile of HTML.
Camping comes with an tool for launching apps from the commandline:

* Run: <tt>camping blog.rb</tt>
* Visit http://localhost:3301/ to use the app.
* Visit http://localhost:3301/blog/ to use the app.

== Debugging Camping Apps

Expand Down
36 changes: 36 additions & 0 deletions lib/camping/fastcgi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'fcgi'

module Camping
class FastCGI
def initialize
@mounts = {}
end
def mount(dir, app)
dir.gsub!(/\/{2,}/, '/')
dir.gsub!(/\/+$/, '')
@mounts[dir] = app
end
def match(path, mount)
m = path.match(/^#{Regexp::quote mount}(\/|$)/)
if m: m.end(0)
else -1
end
end
def start
FCGI.each do |req|
# req.out << app.run(req.in, req.env)
path = req.env['SCRIPT_NAME'] + req.env['PATH_INFO']
dir, app = @mounts.max { |a,b| match(path, a[0]) <=> match(path, b[0]) }
req.env['SCRIPT_NAME'] = dir
req.env['PATH_INFO'] = path.gsub(/^#{dir}/, '')
req.out << app.run(req.in, req.env)
req.finish
end
end
def self.start(app)
cf = Camping::FastCGI.new
cf.mount("/", app)
cf.start
end
end
end

0 comments on commit a81c8a0

Please sign in to comment.