redirect-rails 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redirect/middleware.rb +11 -1
- data/lib/redirect/rails/version.rb +1 -1
- data/lib/redirect/rails.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83fbf537ec5bec148fc7fb605932cc4514ce7cc2f66e7bedc1ab23be6fd2d350
|
4
|
+
data.tar.gz: 55ccabcdf89064ee821d8ec0a00b9a7674d55294496c03b8b6433f382c276d72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c99ff1039100db235d2202d2ae4c4f85414099fc7f25d0b4128f1fcbe9a68c4763aeaa7104ccfaf0bf5130069235325a322e8f85ff655725f4c26b4a99e3392b
|
7
|
+
data.tar.gz: bfec9aac126a0c2e37fb2aaf94eed91c45f0eb47715f897afb077e3c57359882601963e14e80c8e00422089216dc264be97c83f274091cef27aadb28906b7497
|
data/lib/redirect/middleware.rb
CHANGED
@@ -8,13 +8,15 @@ module Redirect
|
|
8
8
|
|
9
9
|
def call(env)
|
10
10
|
@request = Rack::Request.new(env)
|
11
|
-
if url = redirect_url(@request.path)
|
11
|
+
if url = redirect_url(@request.path) || url = redirect_host(@request.host)
|
12
12
|
redirect_to(url)
|
13
13
|
else
|
14
14
|
@app.call(env)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
private
|
19
|
+
|
18
20
|
def redirect_url(request_path)
|
19
21
|
return unless Redirect::Rails.paths
|
20
22
|
|
@@ -23,6 +25,14 @@ module Redirect
|
|
23
25
|
end.first
|
24
26
|
end
|
25
27
|
|
28
|
+
def redirect_host(request_host)
|
29
|
+
return unless Redirect::Rails.hosts
|
30
|
+
|
31
|
+
Redirect::Rails.hosts.map do |host, redirect_url|
|
32
|
+
return ERB.new(redirect_url).result(binding) if Regexp.new(host).match(request_url)
|
33
|
+
end.first
|
34
|
+
end
|
35
|
+
|
26
36
|
def redirect_to(uri)
|
27
37
|
headers = { "Location": uri,
|
28
38
|
"Content-Type": @request["Content-Type"],
|
data/lib/redirect/rails.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redirect-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yusuke
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|