Module: PublicUrl

Defined in:
app/lib/public_url.rb

Class Method Summary collapse

Class Method Details

.hostname ⇒ Object



18
19
20
# File 'app/lib/public_url.rb', line 18

def self.hostname
  ENV.fetch("PUBLIC_HOSTNAME", "localhost")
end

.nonstandard_port ⇒ Object



14
15
16
# File 'app/lib/public_url.rb', line 14

def self.nonstandard_port
  ["80", "443"].include?(port) ? nil : port
end

.port ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'app/lib/public_url.rb', line 2

def self.port
  # PUBLIC_PORT overrides everything
  return ENV.fetch("PUBLIC_PORT") if ENV.key?("PUBLIC_PORT")
  # If hostname is set, assume a standard port
  if ENV.key?("PUBLIC_HOSTNAME")
    https = ENV.fetch("HTTPS_ONLY", nil) === "enabled"
    return https ? "443" : "80"
  end
  # Fall back to RAILS_PORT or default
  ENV.fetch("RAILS_PORT", "3214")
end