This repository has been archived by the owner on Apr 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
87 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
APP_DOMAIN=appfab.dev.io | ||
PORT=3000 | ||
UNICORN_TIMEOUT=60 | ||
UNICORN_WORKERS=3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
APP_DOMAIN=test.host | ||
PUSHER_APP_ID=1234 | ||
PUSHER_KEY=deadbeef | ||
PUSHER_SECRET=deadbeef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# When used, | ||
# All HTTP GET request will be redirected to the canonical app domain | ||
# ENV['APP_DOMAIN'] | ||
module Traits::RedirectToCanonicalDomain | ||
def self.included(by) | ||
by.before_filter :redirect_to_canonical_domain | ||
end | ||
|
||
private | ||
|
||
def redirect_to_canonical_domain | ||
return unless request.method == 'GET' | ||
return if request.host == ENV['APP_DOMAIN'] | ||
|
||
uri = URI.parse(request.url) | ||
uri.host = ENV['APP_DOMAIN'] | ||
uri.scheme = 'https' | ||
|
||
redirect_to uri.to_s | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
spec/controllers/traits/redirect_to_canonical_domain_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require 'spec_helper' | ||
|
||
describe Traits::RedirectToCanonicalDomain, :type => :controller do | ||
controller(ActionController::Base) do | ||
include Traits::RedirectToCanonicalDomain | ||
|
||
def index | ||
head :ok | ||
end | ||
end | ||
|
||
it 'does not redirect for the app host' do | ||
get :index | ||
response.status.should == 200 | ||
end | ||
|
||
context 'when addressing a different host' do | ||
before do | ||
request.host = 'host.host' | ||
end | ||
|
||
it 'redirects GET to canonical domain' do | ||
get :index | ||
response.status.should == 302 | ||
response.headers['Location'].should =~ /test.host/ | ||
end | ||
|
||
it 'redirects with HTTPS' do | ||
get :index | ||
response.headers['Location'].should =~ /^https:/ | ||
end | ||
|
||
it 'does not redirect POST' do | ||
post :index | ||
response.status.should == 200 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters