public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
* Add the --rackup option to load a Rack config file instead of the Rails 
adapter.
  So you can use any framework with the thin script and start cluster and 
  stuff like that.
  A Rack config file is one that is usable through the rackup command and 
  looks like this:

    use Rack::CommonLogger
    run MyCrazyRackAdapter.new(:uterly, 'cool')

  Then use it with thin like this:

    thin start --rackup config.ru
macournoyer (author)
Tue Feb 05 21:26:54 -0800 2008
commit  ab5f77d0156a7bc043278ef61cacf1765719d38a
tree    2b94cc20911c24cfae088fb2f1bb1ad9cf29dbdc
parent  05459cd94191fbd8d88e78aea0bbbb0210f4d85b
...
1
 
 
 
 
 
 
 
 
 
 
 
2
3
4
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
0
@@ -1,4 +1,15 @@
0
 == 0.6.3 Ninja Cookie release
0
+ * Add the --rackup option to load a Rack config file instead of the Rails adapter.
0
+ So you can use any framework with the thin script and start cluster and stuff like that.
0
+ A Rack config file is one that is usable through the rackup command and looks like this:
0
+
0
+ use Rack::CommonLogger
0
+ run MyCrazyRackAdapter.new(:uterly, 'cool')
0
+
0
+ Then use it with thin like this:
0
+
0
+ thin start --rackup config.ru
0
+
0
  * thin config --chrdir ... -C thin/yml do not change current directory anymore, fixes #33.
0
  * Add a better sample god config file in example/thin.god that loads all info from config
0
    files in /etc/thin [Gump].
...
9
10
11
12
 
13
14
15
...
37
38
39
40
 
 
 
 
 
 
 
 
 
41
42
43
...
9
10
11
 
12
13
14
15
...
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
51
0
@@ -9,7 +9,7 @@
0
       end
0
     end
0
   
0
- # Control a Thin server.
0
+ # Controls a Thin server.
0
     # Allow to start, stop, restart and configure a single thin server.
0
     class Controller
0
       include Logging
0
@@ -37,7 +37,15 @@
0
           server.change_privilege @options[:user], @options[:group] if @options[:user] && @options[:group]
0
         end
0
 
0
- server.app = Rack::Adapter::Rails.new(@options.merge(:root => @options[:chdir]))
0
+ # If a Rack config file is specified we eval it inside a Rack::Builder block to create
0
+ # a Rack adapter from it. DHH was hacker of the year a couple years ago so we default
0
+ # to Rails adapter.
0
+ if @options[:rackup]
0
+ rackup_code = File.read(@options[:rackup])
0
+ server.app = eval("Rack::Builder.new {( #{rackup_code}\n )}.to_app", nil, @options[:rackup])
0
+ else
0
+ server.app = Rack::Adapter::Rails.new(@options.merge(:root => @options[:chdir]))
0
+ end
0
 
0
         # If a prefix is required, wrap in Rack URL mapper
0
         server.app = Rack::URLMap.new(@options[:prefix] => server.app) if @options[:prefix]
...
65
66
67
 
 
68
69
70
...
65
66
67
68
69
70
71
72
0
@@ -65,6 +65,8 @@
0
         opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.expand_path(dir) }
0
         opts.on("-t", "--timeout SEC", "Request or command timeout in sec " +
0
                                        "(default: #{@options[:timeout]})") { |sec| @options[:timeout] = sec.to_i }
0
+ opts.on("-r", "--rackup FILE", "Load a Rack config file instead of " +
0
+ "the Rails adapter") { |file| @options[:rackup] = file }
0
         opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| @options[:prefix] = path }
0
         opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| @options[:stats] = path }
0
         
...
39
40
41
42
 
43
44
45
46
47
48
49
 
50
51
52
53
 
 
 
 
 
 
 
54
55
56
...
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
0
@@ -39,18 +39,25 @@
0
     @controller.start
0
   end
0
   
0
- it "should mount app under :prefix" do |variable|
0
+ it "should mount app under :prefix" do
0
     @controller.options[:prefix] = '/app'
0
     @controller.start
0
     
0
     @server.app.class.should == Rack::URLMap
0
   end
0
 
0
- it "should mount Stats adapter under :stats" do |variable|
0
+ it "should mount Stats adapter under :stats" do
0
     @controller.options[:stats] = '/stats'
0
     @controller.start
0
     
0
     @server.app.class.should == Stats::Adapter
0
+ end
0
+
0
+ it "should load app from Rack config" do
0
+ @controller.options[:rackup] = 'example/config.ru'
0
+ @controller.start
0
+
0
+ @server.app.class.should == Proc
0
   end
0
 end
0
 

Comments

    No one has commented yet.