deas 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/deas/rack_request_fix.rb +23 -0
- data/lib/deas/server.rb +8 -3
- data/lib/deas/sinatra_app.rb +21 -17
- data/lib/deas/version.rb +1 -1
- data/lib/deas.rb +3 -0
- data/test/unit/server_tests.rb +10 -2
- data/test/unit/sinatra_app_tests.rb +8 -7
- metadata +5 -4
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
class Rack::Request
|
4
|
+
|
5
|
+
# Pulled from rack master on 2013-05-01. This modifies the rack port lookup
|
6
|
+
# to look at HTTP_X_FORWARDED_PROTO and make a decision. This lookup is
|
7
|
+
# missing from v1.5.2 and causes our Production setup (stunnel and haproxy)
|
8
|
+
# to not work correctly.
|
9
|
+
def port
|
10
|
+
if port = host_with_port.split(/:/)[1]
|
11
|
+
port.to_i
|
12
|
+
elsif port = @env['HTTP_X_FORWARDED_PORT']
|
13
|
+
port.to_i
|
14
|
+
elsif @env.has_key?("HTTP_X_FORWARDED_HOST")
|
15
|
+
DEFAULT_PORTS[scheme]
|
16
|
+
elsif @env.has_key?("HTTP_X_FORWARDED_PROTO")
|
17
|
+
DEFAULT_PORTS[@env['HTTP_X_FORWARDED_PROTO']]
|
18
|
+
else
|
19
|
+
@env["SERVER_PORT"].to_i
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/lib/deas/server.rb
CHANGED
@@ -29,9 +29,10 @@ module Deas
|
|
29
29
|
option :static_files, NsOptions::Boolean, :default => true
|
30
30
|
|
31
31
|
# Deas specific options
|
32
|
-
option :init_proc,
|
33
|
-
option :logger,
|
34
|
-
option :
|
32
|
+
option :init_proc, Proc, :default => proc{ }
|
33
|
+
option :logger, :default => proc{ Deas::NullLogger.new }
|
34
|
+
option :middlewares, Array, :default => []
|
35
|
+
option :verbose_logging, :default => true
|
35
36
|
|
36
37
|
option :routes, Array, :default => []
|
37
38
|
option :view_handler_ns, String
|
@@ -102,6 +103,10 @@ module Deas
|
|
102
103
|
self.configuration.logger *args
|
103
104
|
end
|
104
105
|
|
106
|
+
def use(*args)
|
107
|
+
self.configuration.middlewares << args
|
108
|
+
end
|
109
|
+
|
105
110
|
def verbose_logging(*args)
|
106
111
|
self.configuration.verbose_logging *args
|
107
112
|
end
|
data/lib/deas/sinatra_app.rb
CHANGED
@@ -8,26 +8,30 @@ module Deas
|
|
8
8
|
server_config.init_proc.call
|
9
9
|
server_config.routes.each(&:constantize!)
|
10
10
|
|
11
|
-
|
11
|
+
Sinatra.new do
|
12
12
|
|
13
13
|
# built-in settings
|
14
|
-
|
15
|
-
|
14
|
+
set :environment, server_config.env
|
15
|
+
set :root, server_config.root
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
set :app_file, server_config.app_file
|
18
|
+
set :public_folder, server_config.public_folder
|
19
|
+
set :views, server_config.views_folder
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
set :dump_errors, server_config.dump_errors
|
22
|
+
set :logging, false
|
23
|
+
set :method_override, server_config.method_override
|
24
|
+
set :sessions, server_config.sessions
|
25
|
+
set :show_exceptions, server_config.show_exceptions
|
26
|
+
set :static, server_config.static_files
|
27
27
|
|
28
28
|
# custom settings
|
29
|
-
|
30
|
-
|
29
|
+
set :logger, server_config.logger
|
30
|
+
set :runner_logger, server_config.runner_logger
|
31
|
+
|
32
|
+
server_config.middlewares.each do |middleware_args|
|
33
|
+
use *middleware_args
|
34
|
+
end
|
31
35
|
|
32
36
|
# routes
|
33
37
|
server_config.routes.each do |route|
|
@@ -35,13 +39,13 @@ module Deas
|
|
35
39
|
# before('/'){ ... }
|
36
40
|
# get('/'){ ... }
|
37
41
|
# after('/'){ ... }
|
38
|
-
|
42
|
+
before(route.path) do
|
39
43
|
@runner = route.runner(self).setup
|
40
44
|
end
|
41
|
-
|
45
|
+
send(route.method, route.path) do
|
42
46
|
@runner.run
|
43
47
|
end
|
44
|
-
|
48
|
+
after(route.path) do
|
45
49
|
@runner.teardown
|
46
50
|
end
|
47
51
|
end
|
data/lib/deas/version.rb
CHANGED
data/lib/deas.rb
CHANGED
data/test/unit/server_tests.rb
CHANGED
@@ -23,7 +23,7 @@ class Deas::Server
|
|
23
23
|
subject{ Deas::Server }
|
24
24
|
|
25
25
|
should have_instance_methods :configuration, :init, :view_handler_ns,
|
26
|
-
:get, :post, :put, :patch, :delete, :route
|
26
|
+
:get, :post, :put, :patch, :delete, :route, :use
|
27
27
|
|
28
28
|
should "be a singleton" do
|
29
29
|
assert_includes Singleton, subject.included_modules
|
@@ -59,6 +59,9 @@ class Deas::Server
|
|
59
59
|
subject.static_files false
|
60
60
|
assert_equal false, config.static_files
|
61
61
|
|
62
|
+
subject.use 'MyMiddleware'
|
63
|
+
assert_equal [ ['MyMiddleware'] ], config.middlewares
|
64
|
+
|
62
65
|
stdout_logger = Logger.new(STDOUT)
|
63
66
|
subject.logger stdout_logger
|
64
67
|
assert_equal stdout_logger, config.logger
|
@@ -155,7 +158,8 @@ class Deas::Server
|
|
155
158
|
|
156
159
|
should have_instance_methods :env, :root, :app_file, :public_folder,
|
157
160
|
:views_folder, :dump_errors, :method_override, :sessions, :static_files,
|
158
|
-
:init_proc, :logger, :routes, :view_handler_ns, :show_exceptions
|
161
|
+
:init_proc, :logger, :routes, :view_handler_ns, :show_exceptions,
|
162
|
+
:middlewares
|
159
163
|
|
160
164
|
should "default the env to 'development'" do
|
161
165
|
assert_equal 'development', subject.env
|
@@ -198,6 +202,10 @@ class Deas::Server
|
|
198
202
|
assert_equal [], subject.routes
|
199
203
|
end
|
200
204
|
|
205
|
+
should "default middlewares to an empty array" do
|
206
|
+
assert_equal [], subject.middlewares
|
207
|
+
end
|
208
|
+
|
201
209
|
end
|
202
210
|
|
203
211
|
end
|
@@ -42,19 +42,20 @@ module Deas::SinatraApp
|
|
42
42
|
end
|
43
43
|
|
44
44
|
should "have it's configuration set based on the server configuration" do
|
45
|
-
subject.settings do |settings|
|
46
|
-
assert_equal 'staging', settings.
|
47
|
-
assert_equal 'path/to/somewhere', settings.root
|
45
|
+
subject.settings.tap do |settings|
|
46
|
+
assert_equal 'staging', settings.environment
|
47
|
+
assert_equal 'path/to/somewhere', settings.root.to_s
|
48
48
|
assert_equal @configuration.app_file, settings.app_file
|
49
|
-
assert_equal 'path/to/somewhere/public', settings.public_folder
|
50
|
-
assert_equal 'path/to/somewhere/views', settings.views
|
49
|
+
assert_equal 'path/to/somewhere/public', settings.public_folder.to_s
|
50
|
+
assert_equal 'path/to/somewhere/views', settings.views.to_s
|
51
51
|
assert_equal true, settings.dump_errors
|
52
52
|
assert_equal false, settings.logging
|
53
53
|
assert_equal false, settings.method_override
|
54
54
|
assert_equal false, settings.sessions
|
55
55
|
assert_equal true, settings.show_exceptions
|
56
|
-
assert_equal true, settings.
|
57
|
-
|
56
|
+
assert_equal true, settings.static
|
57
|
+
assert_instance_of Deas::RunnerLogger, settings.runner_logger
|
58
|
+
assert_instance_of Deas::NullLogger, settings.logger
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2013-05-
|
19
|
+
date: 2013-05-02 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
prerelease: false
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- deas.gemspec
|
128
128
|
- lib/deas.rb
|
129
129
|
- lib/deas/logger.rb
|
130
|
+
- lib/deas/rack_request_fix.rb
|
130
131
|
- lib/deas/route.rb
|
131
132
|
- lib/deas/runner.rb
|
132
133
|
- lib/deas/server.rb
|