Redirect to old version of travis for mobile clients
We're planning support for a new mobile client, but for the time being we will just redirect to the old app.
This commit is contained in:
parent
9a0e7d5bb6
commit
7ad4ed1109
|
@ -5,6 +5,8 @@ require 'delegate'
|
||||||
require 'time'
|
require 'time'
|
||||||
|
|
||||||
class Travis::Web::App
|
class Travis::Web::App
|
||||||
|
autoload :MobileRedirect, 'travis/web/app/mobile_redirect'
|
||||||
|
|
||||||
# Simple Rack router that behaves like a hash.
|
# Simple Rack router that behaves like a hash.
|
||||||
# Key is the path, value the response.
|
# Key is the path, value the response.
|
||||||
class Router < DelegateClass(Hash)
|
class Router < DelegateClass(Hash)
|
||||||
|
@ -129,6 +131,7 @@ class Travis::Web::App
|
||||||
builder.use Rack::Deflater
|
builder.use Rack::Deflater
|
||||||
builder.use Rack::Head
|
builder.use Rack::Head
|
||||||
builder.use Rack::ConditionalGet
|
builder.use Rack::ConditionalGet
|
||||||
|
builder.use MobileRedirect
|
||||||
builder.run router
|
builder.run router
|
||||||
builder
|
builder
|
||||||
end
|
end
|
||||||
|
|
12
lib/travis/web/app/mobile_redirect.rb
Normal file
12
lib/travis/web/app/mobile_redirect.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
class Travis::Web::App::MobileRedirect < Struct.new(:app)
|
||||||
|
def call(env)
|
||||||
|
request = Rack::Request.new env
|
||||||
|
|
||||||
|
if request.params['mobile'] || env['HTTP_AGENT'] =~ /Mobile|webOS/
|
||||||
|
location = 'https://secure.travis-ci.org' + request.fullpath
|
||||||
|
[301, { 'Content-Type' => 'text/plain', 'Location' => location }, []]
|
||||||
|
else
|
||||||
|
app.call env
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
20
spec/mobile_redirect_spec.rb
Normal file
20
spec/mobile_redirect_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Travis::Web::App::MobileRedirect do
|
||||||
|
|
||||||
|
describe 'with mobile client' do
|
||||||
|
let(:agent) { 'blah blah Mobile blablah' }
|
||||||
|
|
||||||
|
it 'redirects to secure.travis-ci.org' do
|
||||||
|
get('/foo/bar?baz', {}, 'HTTP_AGENT' => agent).should be_redirect
|
||||||
|
last_response.headers['Location'].should == 'https://secure.travis-ci.org/foo/bar?baz'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'with mobile param' do
|
||||||
|
it 'redirects to secure.travis-ci.org' do
|
||||||
|
get('/foo/bar?baz', mobile: true).should be_redirect
|
||||||
|
last_response.headers['Location'].should == 'https://secure.travis-ci.org/foo/bar?mobile=true&baz'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user