Module: Rack::Handler

Defined in:
lib/rails/local_subdomain/rack/handler.rb

Overview

Override the Rack::Handler to bind to 0.0.0.0 which is required to support lvh.me redirects.

Class Method Summary collapse

Class Method Details

.default(_options = {}) ⇒ Object

rubocop: disable Metrics/MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails/local_subdomain/rack/handler.rb', line 14

def self.default(_options = {})
  orig_default.instance_eval do
    class << self
      alias orig_run run
    end

    def self.run(app, options = {})
      env = (options[:environment] || Rails.env)

      if options[:Host] == 'localhost' &&
         Rails::LocalSubdomain.enabled_in?(env)
        message(options[:Port])
        options[:Host] = '0.0.0.0'
      end
      orig_run(app, options)
    end

    def self.message(port)
      ::Logger.new(STDOUT).info(
        "Binding 'localhost' to '0.0.0.0' for "\
        "http://lvh.me:#{port}/ support")
    end
  end
  orig_default
end

.orig_defaultObject



10
# File 'lib/rails/local_subdomain/rack/handler.rb', line 10

alias orig_default default