Skip to content

Commit

Permalink
make base_url configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
learnjin committed Sep 18, 2014
1 parent 7b79413 commit 23ce741
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/rack/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ module Rewritten

class Url

attr_accessor :base_url

def initialize(app, &block)
@app = app
@translate_backwards = false
@downcase_before_lookup = false
@translate_partial = false
@base_url = ''
instance_eval(&block) if block_given?
end

def is_internal_target?(url)
url.nil? or url.start_with?('/') or url.start_with?('http://www.example.org')
url.nil? or url.start_with?('/') or url.start_with?(@base_url)
end

def is_external_target?(url)
Expand Down
4 changes: 3 additions & 1 deletion test/rack/rewritten_url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def request_url(url, params={})

before {
@app = MiniTest::Mock.new
@rack = Rack::Rewritten::Url.new(@app)
@rack = Rack::Rewritten::Url.new(@app) do |config|
config.base_url = 'http://www.example.org'
end

Rewritten.add_translation '/external/target', 'http://www.external.com'
}
Expand Down

0 comments on commit 23ce741

Please sign in to comment.