如何在Rails上禁用“无法渲染控制台…”

时间:2023-01-16 09:39:11

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

我使用Ubuntu/vagrant作为我的开发环境。我在rails控制台得到这些消息:

Started GET "/assets/home-fcec5b5a277ac7c20cc9f45a209a3bcd.js?body=1" for 10.0.2.2 at 2015-04-02 15:48:31 +0000
Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255

Is it possible to disable those "cannot render..." messages or allow them in any way?

是否有可能禁用那些“不能渲染…”的消息或以任何方式允许它们?

7 个解决方案

#1


126  

You need to whitelist the 10.0.2.2 network space in the Web Console config.

您需要在Web控制台配置中白列10.0.2.2网络空间。

So you'll want something like this:

你会想要这样的东西:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '10.0.2.2'
end

Read here for more information.

更多信息请阅读这里。

As pointed out by pguardiario, this wants to go into config/environments/development.rb rather than config/application.rb so it is only applied in your development environment.

正如pguardiario所指出的,这需要进入配置/环境/开发。rb而不是配置/应用程序。所以它只适用于您的开发环境。

#2


67  

You can whitelist single IP's or whole networks.

Say you want to share your console with 192.168.0.100. You can do this:

假设您希望与192.168.0.100共享您的控制台。你可以这样做:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '192.168.0.100'
end

If you want to whitelist the whole private network, you can do:

如果你想要将整个私人网络列入白名单,你可以:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '192.168.0.0/16'
end

If you don't wanna see this message anymore, set this option to false:

class Application < Rails::Application
  config.web_console.whiny_requests = false
end

Be careful what you wish for, 'cause you might just get it all

This is probably only for development purposes so you might prefer to place it under config/environments/development.rb instead of config/application.rb.

这可能只用于开发目的,所以您可能更喜欢将它放在配置/环境/开发中。rb的配置/ application.rb。

#3


22  

Hardcoding an IP into a configuration file isn't good. What about other devs? What if the ip changes?

将IP硬编码到配置文件中并不好。其他开发者呢?如果ip改变了怎么办?

Docker-related config should not leak into the rails app whenever possible. That's why you should use env vars in the config/environments/development.rb file:

docker相关的配置不应该在任何可能的时候泄露到rails应用程序中。这就是为什么您应该在配置/环境/开发中使用env vars。rb文件:

class Application < Rails::Application
  # Check if we use Docker to allow docker ip through web-console
  if ENV['DOCKERIZED'] == 'true'
    config.web_console.whitelisted_ips = ENV['DOCKER_HOST_IP']
  end
end

You should set correct env vars in a .env file, not tracked into version control.

您应该在.env文件中设置正确的env vars,而不是跟踪到版本控制中。

In docker-compose.yml you can inject env vars from this file with env_file:

在docker-compose。yml:您可以使用env_file从这个文件中注入env vars:

app:
  build: .
  ports:
   - "3000:3000"
  volumes:
    - .:/app
  links:
    - db
  environment:
    - DOCKERIZED=true
  env_file:
    - ".env"

#4


13  

Auto discovery within your config/development.rb

在配置/开发中自动发现

config.web_console.whitelisted_ips = Socket.ip_address_list.reduce([]) do |res, addrinfo|
    addrinfo.ipv4? ? res << IPAddr.new(addrinfo.ip_address).mask(24) : res
end

Of course might need to add

当然可能需要添加

require 'socket'
require 'ipaddr'

Within your file.

在你的文件。

#5


5  

Anyone on any of my private networks is welcome.

任何人在我的任何私人网络欢迎。

I run in a docker container and I don't care which network it wants to use this week.

我在docker容器中运行,我不关心这个星期它想要使用哪个网络。

config/environments/development.rb add line

配置/环境/发展。rb添加行

config.web_console.whitelisted_ips = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']

#6


1  

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

对于开发环境:检测它是否是docker,然后确定IP地址并将其白名单

# 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 ????

对我来说这个打印以下消失????和警告

Adding 172.27.0.0 to config.web_console.whitelisted_ips
Adding 172.18.0.0 to config.web_console.whitelisted_ips

My solution was to combine

我的解决办法是合并

#7


0  

If you want to stop seeing this error message you can add this line in development.rb

如果您不想看到这个错误消息,可以在development.rb中添加这一行

config.web_console.whiny_requests = false

#1


126  

You need to whitelist the 10.0.2.2 network space in the Web Console config.

您需要在Web控制台配置中白列10.0.2.2网络空间。

So you'll want something like this:

你会想要这样的东西:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '10.0.2.2'
end

Read here for more information.

更多信息请阅读这里。

As pointed out by pguardiario, this wants to go into config/environments/development.rb rather than config/application.rb so it is only applied in your development environment.

正如pguardiario所指出的,这需要进入配置/环境/开发。rb而不是配置/应用程序。所以它只适用于您的开发环境。

#2


67  

You can whitelist single IP's or whole networks.

Say you want to share your console with 192.168.0.100. You can do this:

假设您希望与192.168.0.100共享您的控制台。你可以这样做:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '192.168.0.100'
end

If you want to whitelist the whole private network, you can do:

如果你想要将整个私人网络列入白名单,你可以:

class Application < Rails::Application
  config.web_console.whitelisted_ips = '192.168.0.0/16'
end

If you don't wanna see this message anymore, set this option to false:

class Application < Rails::Application
  config.web_console.whiny_requests = false
end

Be careful what you wish for, 'cause you might just get it all

This is probably only for development purposes so you might prefer to place it under config/environments/development.rb instead of config/application.rb.

这可能只用于开发目的,所以您可能更喜欢将它放在配置/环境/开发中。rb的配置/ application.rb。

#3


22  

Hardcoding an IP into a configuration file isn't good. What about other devs? What if the ip changes?

将IP硬编码到配置文件中并不好。其他开发者呢?如果ip改变了怎么办?

Docker-related config should not leak into the rails app whenever possible. That's why you should use env vars in the config/environments/development.rb file:

docker相关的配置不应该在任何可能的时候泄露到rails应用程序中。这就是为什么您应该在配置/环境/开发中使用env vars。rb文件:

class Application < Rails::Application
  # Check if we use Docker to allow docker ip through web-console
  if ENV['DOCKERIZED'] == 'true'
    config.web_console.whitelisted_ips = ENV['DOCKER_HOST_IP']
  end
end

You should set correct env vars in a .env file, not tracked into version control.

您应该在.env文件中设置正确的env vars,而不是跟踪到版本控制中。

In docker-compose.yml you can inject env vars from this file with env_file:

在docker-compose。yml:您可以使用env_file从这个文件中注入env vars:

app:
  build: .
  ports:
   - "3000:3000"
  volumes:
    - .:/app
  links:
    - db
  environment:
    - DOCKERIZED=true
  env_file:
    - ".env"

#4


13  

Auto discovery within your config/development.rb

在配置/开发中自动发现

config.web_console.whitelisted_ips = Socket.ip_address_list.reduce([]) do |res, addrinfo|
    addrinfo.ipv4? ? res << IPAddr.new(addrinfo.ip_address).mask(24) : res
end

Of course might need to add

当然可能需要添加

require 'socket'
require 'ipaddr'

Within your file.

在你的文件。

#5


5  

Anyone on any of my private networks is welcome.

任何人在我的任何私人网络欢迎。

I run in a docker container and I don't care which network it wants to use this week.

我在docker容器中运行,我不关心这个星期它想要使用哪个网络。

config/environments/development.rb add line

配置/环境/发展。rb添加行

config.web_console.whitelisted_ips = ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16']

#6


1  

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

对于开发环境:检测它是否是docker,然后确定IP地址并将其白名单

# 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 ????

对我来说这个打印以下消失????和警告

Adding 172.27.0.0 to config.web_console.whitelisted_ips
Adding 172.18.0.0 to config.web_console.whitelisted_ips

My solution was to combine

我的解决办法是合并

#7


0  

If you want to stop seeing this error message you can add this line in development.rb

如果您不想看到这个错误消息,可以在development.rb中添加这一行

config.web_console.whiny_requests = false