Module: Rack::Handler

Defined in:
lib/local-subdomain/rack/handler.rb

Class Method Summary collapse

Class Method Details

.default(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/local-subdomain/rack/handler.rb', line 10

def self.default(options = {})
  orig_default.instance_eval do
    class << self
      alias_method :orig_run, :run
    end

    def self.run(app, options = {})
      env = (options[:environment] || Rails.env)
      if options[:Host] == 'localhost' && env == 'development'
        message(options[:Port])
        options.merge!(Host: '0.0.0.0')
      end
      orig_run(app, options)
    end

    def self.message(port)
      puts '****************************************************************************************'
      puts "* Override binding 'localhost' to '0.0.0.0' for http://lvh.me:#{port}/ support"
      puts '****************************************************************************************'
    end
  end
  orig_default
end

.orig_defaultObject



7
# File 'lib/local-subdomain/rack/handler.rb', line 7

alias_method :orig_default, :default