force_domain 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1777375bec585874d6a8903710d90093aa9f3e22
4
- data.tar.gz: 5e35732ad54030556df24e6f60ca62d4fada0bc0
3
+ metadata.gz: 797effcc595888f154d287ab3cf9fc1cba02373d
4
+ data.tar.gz: cafe4463bc84647ea8db7a26fcdb686b2836ee4f
5
5
  SHA512:
6
- metadata.gz: a712c9b48135f7efcb4b7fb41c92f8bc4d49d0650c0820a44f6df514b399a3d0a5c42ed530b31f1b0f577ede80ebff091df16c2049cefa1e825869041bff2041
7
- data.tar.gz: 6050be498667b04969ced7b4b70b8482dda645c7a20c4cca753a8af18ce8adeb71fd38273500f09e0f95bcb052fffd914fb11a9ed01298c1bf84526841a40c0c
6
+ metadata.gz: 3e8ed4ff1337ca70ef5f6748366a6db3a29d638eaaf55143a3324a91b69d0d01839d3bd9386cefb9eec21397ef48fea3b568af3e15bb9900ab848ffbcb864f2e
7
+ data.tar.gz: 5df4514f9c44297332ff93e409b0ffcc701542ef30d4121bb8b0e7e3f7f8c25e9d548a7f00c8d603d4606d315137e6f1c6ca0250c4bb7d663f95a90a3ba64038
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # ForceDomain
2
2
 
3
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -0,0 +1,7 @@
1
+ module ForceDomain
2
+ class Railtie < Rails::Railtie
3
+ initializer "force_domain.configure_rails_initialization" do
4
+ Rails.application.middleware.use ForceDomain::Middleware
5
+ end
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module ForceDomain
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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.1
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: