force_domain 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +20 -2
- data/lib/force_domain/middleware.rb +29 -0
- data/lib/force_domain/railtie.rb +7 -0
- data/lib/force_domain/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 797effcc595888f154d287ab3cf9fc1cba02373d
|
4
|
+
data.tar.gz: cafe4463bc84647ea8db7a26fcdb686b2836ee4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e8ed4ff1337ca70ef5f6748366a6db3a29d638eaaf55143a3324a91b69d0d01839d3bd9386cefb9eec21397ef48fea3b568af3e15bb9900ab848ffbcb864f2e
|
7
|
+
data.tar.gz: 5df4514f9c44297332ff93e409b0ffcc701542ef30d4121bb8b0e7e3f7f8c25e9d548a7f00c8d603d4606d315137e6f1c6ca0250c4bb7d663f95a90a3ba64038
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ForceDomain
|
2
2
|
|
3
|
-
|
3
|
+
Rack middleware that will redirect all request that are not from the specified domain
|
4
|
+
|
5
|
+
Useful for redirecting website.herokuapp.com to www.website.com
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -18,7 +20,23 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
21
|
-
|
23
|
+
If your using Rails, the middleware will be inserted automatically
|
24
|
+
|
25
|
+
Otherwise you have to insert it manually
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
use ForceDomain::Middleware
|
29
|
+
```
|
30
|
+
|
31
|
+
Now all you need to do is set the environment key `APP_DOMAIN` to your specific domain
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
```shell
|
36
|
+
heroku config:set APP_DOMAIN=www.website.com
|
37
|
+
```
|
38
|
+
|
39
|
+
All requests made to website.herokuapp.com will now 301 redirect to www.website.com keeping path and query parameters
|
22
40
|
|
23
41
|
## Contributing
|
24
42
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ForceDomain
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if ENV['APP_DOMAIN'] && env['HTTP_HOST'] != ENV['APP_DOMAIN']
|
9
|
+
[301, {'Location' => new_location(env), 'Content-Type' => 'text/html', 'Content-Length' => '0'}, []]
|
10
|
+
else
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def new_location(env)
|
18
|
+
scheme = env['rack.url_scheme']
|
19
|
+
domain = ENV['APP_DOMAIN']
|
20
|
+
path = env['PATH_INFO']
|
21
|
+
query_string = env['QUERY_STRING'].to_s
|
22
|
+
|
23
|
+
location = "#{scheme}://#{domain}#{path}"
|
24
|
+
location << "?#{query_string}" unless query_string.empty?
|
25
|
+
|
26
|
+
location
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/force_domain/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: force_domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aske Hansen
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- Rakefile
|
54
54
|
- force_domain.gemspec
|
55
55
|
- lib/force_domain.rb
|
56
|
+
- lib/force_domain/middleware.rb
|
57
|
+
- lib/force_domain/railtie.rb
|
56
58
|
- lib/force_domain/version.rb
|
57
59
|
homepage: https://github.com/askehansen/force_domain
|
58
60
|
licenses:
|