Module: Proximity
- Extended by:
- Configuration
- Defined in:
- lib/proximity.rb,
lib/proximity/dsl.rb,
lib/proximity/proxy.rb,
lib/proximity/utils.rb,
lib/proximity/router.rb,
lib/proximity/routes.rb,
lib/proximity/version.rb,
lib/proximity/proxy_set.rb,
lib/proximity/route_set.rb,
lib/proximity/configuration.rb
Defined Under Namespace
Modules: ClassMethods, Configuration, Dsl, Utils
Classes: Proxy, ProxySet, RouteSet, Router, Routes
Constant Summary
collapse
- RoutingError =
Class.new(StandardError)
- VERSION =
"1.1.0"
Class Method Summary
collapse
Instance Method Summary
collapse
engine, env, pathPatternClass, routerClass, routesClass
Class Method Details
.included(base) ⇒ Object
12
13
14
|
# File 'lib/proximity.rb', line 12
def self.included(base)
base.extend ClassMethods
end
|
Instance Method Details
#call(env) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/proximity.rb', line 22
def call(env)
route_env(env)
super
rescue RoutingError => e
= {'Content-Type' => 'text/plain', 'Content-Length' => e.message.length}
[404, , [e.message]]
end
|
#route(env) ⇒ Object
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/proximity.rb', line 43
def route(env)
match = router.match(env)
if match
uri = URI.parse(match.target)
[uri.host, uri.path]
else
raise RoutingError.new("The path: #{env['PATH_INFO']} does not match any proxy routes.")
end
end
|
#route_env(env) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/proximity.rb', line 30
def route_env(env)
host, path = route(env)
env.tap { |e|
e['SCRIPT_NAME'] = ''
e['HTTP_HOST'] = host
e['PATH_INFO'] = path
}
end
|
#router ⇒ Object
39
40
41
|
# File 'lib/proximity.rb', line 39
def router
self.class.routes.router
end
|