public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Add prefix option to thin script to mount app under a given path.
macournoyer (author)
Sun Jan 13 19:50:28 -0800 2008
commit  d0e2e14d0637bf8f2a6be3a159848e6a516e6ffc
tree    0786612a840fe0d4486f6490dcd75d34bd5ac128
parent  40f62a8fe7ea9dc6304a90efbd1b6682e5ae25b7
...
 
 
 
1
2
3
...
1
2
3
4
5
6
0
@@ -1,3 +1,6 @@
0
+== 0.5.3 Purple Yogurt release
0
+ * Add prefix option to thin script to mount app under a given path.
0
+
0
 == 0.5.2 Cheezburger release
0
  * Add cluster support through the -s option in the thin script, start 3 thins like this:
0
     thin start -s3 -p3000
...
43
44
45
 
46
47
48
...
77
78
79
 
 
 
 
80
81
82
...
43
44
45
46
47
48
49
...
78
79
80
81
82
83
84
85
86
87
0
@@ -43,6 +43,7 @@ opts = OptionParser.new do |opts|
0
                                  "(default: #{options[:timeout]})") { |sec| options[:timeout] = sec.to_i }
0
   opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
0
   opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
0
+ opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| options[:prefix] = path }
0
   
0
   opts.separator ""
0
   opts.separator "Common options:"
0
@@ -77,6 +78,10 @@ def start(options)
0
     end
0
   
0
     server.app = Rack::Adapter::Rails.new(options.merge(:root => options[:chdir]))
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]
0
+
0
     server.start!
0
   end
0
 end
...
14
15
16
17
18
 
 
 
19
20
21
...
27
28
29
 
 
30
31
32
...
14
15
16
 
 
17
18
19
20
21
22
...
28
29
30
31
32
33
34
35
0
@@ -14,8 +14,9 @@ module Rack
0
   module Adapter
0
     class Rails
0
       def initialize(options={})
0
- @root = options[:root] || Dir.pwd
0
- @env = options[:environment] || 'development'
0
+ @root = options[:root] || Dir.pwd
0
+ @env = options[:environment] || 'development'
0
+ @prefix = options[:prefix]
0
         
0
         load_application
0
         
0
@@ -27,6 +28,8 @@ module Rack
0
 
0
         require "#{@root}/config/environment"
0
         require 'dispatcher'
0
+
0
+ ActionController::AbstractRequest.relative_url_root = @prefix if @prefix
0
       end
0
       
0
       # TODO refactor this in File#can_serve?(path) ??
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ module Thin
0
         body << data
0
       elsif @data.size > MAX_HEADER # Oho! very big header, must be a mean person
0
        raise InvalidRequest, MAX_HEADER_MSG
0
- else # Parse more header
0
+ else # Parse more header using the super parser
0
        @nparsed = @parser.execute(@env, @data, @nparsed)
0
       end
0
       
...
2
3
4
5
 
6
7
8
9
 
10
11
...
2
3
4
 
5
6
7
8
 
9
10
11
0
@@ -2,10 +2,10 @@ module Thin
0
   module VERSION #:nodoc:
0
     MAJOR = 0
0
     MINOR = 5
0
- TINY = 2
0
+ TINY = 3
0
 
0
     STRING = [MAJOR, MINOR, TINY].join('.')
0
     
0
- CODENAME = 'Cheezburger'
0
+ CODENAME = 'Purple Yogurt'
0
   end
0
 end
...
138
139
140
 
141
142
143
...
138
139
140
141
142
143
144
0
@@ -138,6 +138,7 @@ class Thin < Atchoum::Website
0
       li { a "Kevin Williams Blog", :href => 'http://www.almostserio.us/articles/2008/01/11/thin-web-server-for-ruby-rocks' }
0
       li { a "Dinooz", :href => 'http://www.nicomoayudarte.com/' }
0
       li { a "Mobile Dyne Systems", :href => 'http://www.mobiledyne.com/' }
0
+ li { a "Mobile Dyne Systems", :href => 'http://feelfree.homelinux.com' }
0
     end
0
     
0
     p { "If you'd like to have your site listed here, #{a 'drop me an email', :href => 'mailto:macournoyer@gmail.com'}" }
...
4
5
6
7
 
8
9
10
...
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
...
4
5
6
 
7
8
9
10
...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -4,7 +4,7 @@ require 'rack/mock'
0
 begin
0
   gem 'rails', '= 2.0.2' # We could freeze Rails in the rails_app dir to remove this
0
 
0
- context Rack::Adapter::Rails do
0
+ describe Rack::Adapter::Rails do
0
     before do
0
       @rails_app_path = File.dirname(__FILE__) + '/rails_app'
0
       @request = Rack::MockRequest.new(Rack::Adapter::Rails.new(:root => @rails_app_path))
0
@@ -67,6 +67,25 @@ begin
0
       FileUtils.rm_rf @rails_app_path + '/public/simple'
0
     end
0
   end
0
+
0
+ describe Rack::Adapter::Rails, 'with prefix' do
0
+ before do
0
+ @rails_app_path = File.dirname(__FILE__) + '/rails_app'
0
+ @prefix = '/nowhere'
0
+ @request = Rack::MockRequest.new(
0
+ Rack::URLMap.new(
0
+ @prefix => Rack::Adapter::Rails.new(:root => @rails_app_path, :prefix => @prefix)))
0
+ end
0
+
0
+ it "should handle simple GET request" do
0
+ res = @request.get("#{@prefix}/simple", :lint => true)
0
+
0
+ res.should be_ok
0
+ res["Content-Type"].should include("text/html")
0
+
0
+ res.body.should include('Simple#index')
0
+ end
0
+ end
0
 
0
 rescue Gem::LoadError
0
   warn 'Rails 2.0.2 is required to run the Rails adapter specs'

Comments

    No one has commented yet.