public
Description: A new revision of Fuzed, the Erlang-based frontend for web apps. Check out the mailing list at http://groups.google.com/group/fuzed
Homepage:
Clone URL: git://github.com/KirinDave/fuzed.git
fuzed / rlibs / rails_node.rb
100644 68 lines (60 sloc) 2.152 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$rails_json = true
 
# core
require 'optparse'
 
# internal
require 'chassis'
require 'rails_adapter'
require 'fuzed_handler'
 
# read command line options
options = {}
opts = OptionParser.new do |opts|
  opts.on("-r", "--rails-root RAILS_ROOT", String) do |x|
    options[:rails_root] = x
  end
  opts.on("-t", "--test", "enable test mode") do
    options[:test] = true
  end
  opts.on("-e", "--rails-env ENV", String) do |x|
    options[:rails_env] = x
  end
end
opts.parse(ARGV)
options[:rails_root] = File.join(File.dirname(__FILE__), *%w[.. test app]) if options[:test]
options[:rails_env] ||= 'development'
 
# app
app = Rack::Adapter::Rails.new(:root => options[:rails_root], :environment => options[:rails_env])
logfile = options[:rails_root] + "/log/fuzed.#{Process.pid}.log"
$handler = Rack::Handler::Fuzed.new(app, logfile)
 
# chassis
class RailsHandler < Chassis
  kind "rails"
 
  handle(:handle_request, :request) do |args|
    $handler.service(args[:request])
  end
end
 
# test mode
if options[:test]
  req =
  {:method => :POST,
   :http_version => [1, 1],
   :querypath => "/main/go",
   :querydata => "",
   :servername => "testing:8002",
   :headers => {:connection => "keep-alive",
                :accept => "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",
                :host => "localhost:8002",
                :referer => "http://localhost:8002/main/ready",
                :user_agent => "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3",
                :keep_alive => "300",
                :content_length => "7",
                :content_type => "application/x-www-form-urlencoded",
                :"Cache-Control" => "max-age=0",
                :"Accept-Charset" => "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
                :"Accept-Encoding" => "gzip,deflate",
                :"Accept-Language" => "en-us,en;q=0.5"},
   :cookies => ["_helloworld_session_id=d3eae987aab3230377abc433b7a8d7c1"],
   :pathinfo => "/Users/tom/dev/fuzed/helloworld/public",
   :postdata => "val=foo"}
  
  p $handler.service(req)
  exit!
end