ensure_subdomain 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -28
- data/lib/ensure_subdomain.rb +9 -0
- data/lib/ensure_subdomain/version.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccd1b4114ecac9dc8ae497064e242726a558ddb4
|
4
|
+
data.tar.gz: 95b1c2939531da295e2cdeff6d0b7ee857110ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bdc5bee8f1883666e0d786e285b989c8783e925f7f81512b8c359674abe23b99c436c63e8c45daee146893c3746bf2ea35db08f02e785bb242a5e2ef7c1b539
|
7
|
+
data.tar.gz: 98a715b2ad1d052f25a97ab0a8ed79e7115efac88fde1a92495cb98b297f36fba23dd0696d011ebe690460f60d9535c43e3f45c4c4d91224c9d5bb5dfa1acad5
|
data/README.md
CHANGED
@@ -1,41 +1,68 @@
|
|
1
|
-
#
|
1
|
+
# Ensure Subdomain
|
2
2
|
|
3
|
-
|
3
|
+
_an ActionDispatch extension to handle subdomain redirects_
|
4
4
|
|
5
5
|
Let's say you believe that [using the www subdomain is dumb](http://no-www.org).
|
6
|
+
|
6
7
|
Ensuring your rails app doesn't use this subdomain is pretty easy, but now it's easier.
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
```ruby
|
10
|
+
# Gemfile
|
11
|
+
gem 'ensure_subdomain'
|
12
|
+
|
13
|
+
# Preferred terminal
|
14
|
+
`bundle install`
|
15
|
+
|
16
|
+
# config/routes.rb
|
17
|
+
Rails.application.routes.draw do
|
18
|
+
ensure_apex # or ensure_no_www or ensure_non_www
|
19
|
+
|
20
|
+
# The rest of my cool routes
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
GET www.example.com → 301 example.com
|
25
|
+
|
22
26
|
Simple as that.
|
23
27
|
|
24
28
|
Conversely, if you are wrong and think you should use www, there's a method for that.
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
+
```ruby
|
31
|
+
# config/routes.rb
|
32
|
+
Rails.application.routes.draw do
|
33
|
+
ensure_www
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
GET example.com → 301 www.example.com
|
38
|
+
|
39
|
+
|
40
|
+
If you've got some other domain, there's a method for that too.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
# config/routes.rb
|
44
|
+
Rails.application.routes.draw do
|
45
|
+
ensure_subdomain 'blog'
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
GET example.com → 301 blog.example.com
|
50
|
+
|
51
|
+
GET www.example.com → 301 blog.example.com
|
52
|
+
|
53
|
+
What if you want to control the direction for different environments? I've got ya.
|
30
54
|
|
31
|
-
|
55
|
+
```ruby
|
56
|
+
# config/routes.rb
|
57
|
+
Rails.application.routes.draw do
|
58
|
+
ensure_on production: 'www',
|
59
|
+
staging: 'staging',
|
60
|
+
development: 'dev'
|
61
|
+
end
|
62
|
+
```
|
32
63
|
|
64
|
+
Also recently added, and somewhat experimental, _not fucking up on Heroku!_
|
33
65
|
|
34
|
-
|
66
|
+
*Before:* GET application.herokuapp.com → 301 herokuapp.com → 301 heroku.com
|
35
67
|
|
36
|
-
|
37
|
-
My::Application.routes.draw do
|
38
|
-
ensure_subdomain 'blog'
|
39
|
-
end
|
40
|
-
|
41
|
-
GETting http://my-app.dev/ will redirect to http://blog.my-app.dev
|
68
|
+
*After:* GET application.herokuapp.com
|
data/lib/ensure_subdomain.rb
CHANGED
@@ -31,11 +31,20 @@ module ActionDispatch::Routing::Mapper::HttpHelpers
|
|
31
31
|
ensure_subdomain ''
|
32
32
|
end
|
33
33
|
alias_method :ensure_non_www, :ensure_no_www
|
34
|
+
alias_method :ensure_apex, :ensure_no_www
|
34
35
|
|
35
36
|
def ensure_www
|
36
37
|
ensure_subdomain 'www'
|
37
38
|
end
|
38
39
|
|
40
|
+
def ensure_on(environments)
|
41
|
+
environments.each_pair do |env, domain|
|
42
|
+
if Rails.env.to_sym == env
|
43
|
+
ensure_subdomain domain
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
39
48
|
def ensure_subdomain(subdomain, options={})
|
40
49
|
redirector = EnsureSubdomain.new( subdomain )
|
41
50
|
verbs = options[:via] || [:get, :post, :put, :patch, :delete]
|