Skip to content
This repository has been archived by the owner on Apr 26, 2022. It is now read-only.

Commit

Permalink
Merge 536145d into 05601af
Browse files Browse the repository at this point in the history
  • Loading branch information
mezis committed Feb 2, 2014
2 parents 05601af + 536145d commit f0df0a9
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env
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
Expand Down
1 change: 1 addition & 0 deletions .env.test
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
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ group :development do
gem 'nifty-generators', require:false

# debugging
gem 'pry', require:false
gem 'pry-nav', require:false
gem 'pry-doc', require:false
gem 'pry'
gem 'pry-nav'
gem 'pry-doc'
gem 'pry-rails'
gem 'pry-remote'
gem 'ruby-prof', require:false

# tdd
Expand Down
18 changes: 11 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
activerecord (>= 3.2.0, < 5.0)

GEM
remote: https://rubygems.org/
remote: http://yarp.dev/
specs:
actionmailer (4.0.2)
actionpack (= 4.0.2)
Expand Down Expand Up @@ -63,7 +63,7 @@ GEM
childprocess (0.3.9)
ffi (~> 1.0, >= 1.0.11)
chunky_png (1.2.9)
coderay (1.0.9)
coderay (1.1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.0.1)
Expand Down Expand Up @@ -262,17 +262,20 @@ GEM
faye-websocket (~> 0.4.4)
http_parser.rb (~> 0.5.3)
polyglot (0.3.3)
pry (0.9.12.2)
coderay (~> 1.0.5)
pry (0.9.12.6)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
pry-doc (0.4.6)
pry-doc (0.5.1)
pry (>= 0.9)
yard (>= 0.8)
pry-nav (0.2.3)
pry (~> 0.9.10)
pry-rails (0.3.2)
pry (>= 0.9.10)
pry-remote (0.1.8)
pry (~> 0.9)
slop (~> 3.0)
pusher (0.12.0)
httpclient (~> 2.3.0)
multi_json (~> 1.0)
Expand Down Expand Up @@ -375,7 +378,7 @@ GEM
simplecov-html (0.7.1)
sinatra (1.0)
rack (>= 1.0)
slop (3.4.6)
slop (3.4.7)
sprockets (2.10.1)
hike (~> 1.2)
multi_json (~> 1.0)
Expand Down Expand Up @@ -434,7 +437,7 @@ GEM
xpath (1.0.0)
nokogiri (~> 1.3)
yamler (0.1.0)
yard (0.8.7.1)
yard (0.8.7.3)

PLATFORMS
ruby
Expand Down Expand Up @@ -488,6 +491,7 @@ DEPENDENCIES
pry-doc
pry-nav
pry-rails
pry-remote
pusher
pusher-fake
query_reviewer
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ through voting, and follow them through their whole lifecycle.

### Setup

AppFab requires `Ruby 2.0`, `Postgresql` and `MemCache` to be installed.
AppFab requires `Ruby 2.1`, `PostgreSQL` and `memcached` to be installed.

With those installed you can setup the application by running: `./bin/setup`

Locally, it is preferable to use [Pow](http://pow.cx/) with to run Appfab, using
the `.dev.io` local domain. If you do not want to use pow, configure `.env`
with `APP_DOMAIN=localhost`. This is because Appfab will make attempts to
redirect you to a canonical domain.

If you want to test SSL redirections, we recommend to use
[tunnels](https://github.com/jugyo/tunnels) in conjunction with Pow--it's the
simplest way to serve SSL locally.

### Usage

Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery

include Traits::RedirectToCanonicalDomain
include Traits::RedirectToHttps
include Traits::RenderUjs
include Traits::FlashesInHeaders
Expand Down
21 changes: 21 additions & 0 deletions app/controllers/traits/redirect_to_canonical_domain.rb
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 spec/controllers/traits/redirect_to_canonical_domain_spec.rb
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
2 changes: 1 addition & 1 deletion spec/controllers/traits/redirect_to_http_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Traits::RedirectToHttps, :type => :controller do
controller do
controller(ActionController::Base) do
include Traits::RedirectToHttps

def index
Expand Down

0 comments on commit f0df0a9

Please sign in to comment.