Module: Portless::RailsHosts
- Defined in:
- lib/portless/rails_hosts.rb
Overview
The host matchers to whitelist in Rails development, derived from the URL
rb-portless run injects (PORTLESS_URL). Plain Ruby so it's testable without
booting Rails; the Railtie is just glue around it.
Class Method Summary collapse
-
.allowed(portless_url = ENV["PORTLESS_URL"]) ⇒ Object
Empty unless we're actually running under rb-portless.
Class Method Details
.allowed(portless_url = ENV["PORTLESS_URL"]) ⇒ Object
Empty unless we're actually running under rb-portless.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/portless/rails_hosts.rb', line 13 def allowed(portless_url = ENV["PORTLESS_URL"]) return [] if portless_url.to_s.empty? # Rails wraps a Regexp as /\A<re>(:port)?\z/, so match the whole host. patterns = [ /.+\.localhost/ ] host = begin URI(portless_url).host rescue StandardError nil end # Support a custom, non-.localhost tld (e.g. *.myapp.test) too. patterns.push(host, ".#{host}") if host && !host.end_with?(".localhost") patterns end |