How to disable “Cannot Render Console from…” on Rails

后端 未结 11 1281
心在旅途
心在旅途 2020-12-07 10:35

I\'m using Ubuntu/vagrant as my development environment. I\'m getting these messages on rails console:

Started GET \"/assets/home-fcec5b5a277ac7c20cc9f45a209         


        
11条回答
  •  北海茫月
    2020-12-07 11:05

    For development environment: Detect if it's docker, then determine the IP address and whitelist it

    # config/environments/development.rb
    require 'socket'
    require 'ipaddr'
    
    Rails.application.configure do
      ...
    
      # When inside a docker container
      if File.file?('/.dockerenv')
        # Whitelist docker ip for web console
        # Cannot render console from 172.27.0.1! Allowed networks: 127.0.0.1
        Socket.ip_address_list.each do |addrinfo|
          next unless addrinfo.ipv4?
          next if addrinfo.ip_address == "127.0.0.1" # Already whitelisted
    
          ip = IPAddr.new(addrinfo.ip_address).mask(24)
    
          Logger.new(STDOUT).info "Adding #{ip.inspect} to config.web_console.whitelisted_ips"
    
          config.web_console.whitelisted_ips << ip
        end
      end
    end
    

    For me this prints the following and the warning goes away

提交回复
热议问题