gpt4 book ai didi

ruby-on-rails - 如何配置 Rails 5.2.1 服务器监听所有接口(interface)?

转载 作者:数据小太阳 更新时间:2023-10-29 07:58:16 25 4
gpt4 key购买 nike

我对 RoR 和学习还很陌生,所以如果我有后续问题,请多多包涵。我们的 Rails (v 5.0.2) 应用程序配置为在 config/boot.rb 中使用此配置监听所有接口(interface):

require 'rails/commands/server'
module Rails
class Server
def default_options
# make rails listen on all interfaces (accept connections from any ip)
super.merge(Host: '0.0.0.0', Port: 1234)
end
end
end

我最近将 Rails 从 5.0.2 升级到 5.2.1,当我运行 rails s 时,我得到:

/Users/aum/rails_app/config/boot.rb:5:in `require': cannot load such file -- rails/commands/server (LoadError)
from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
from bin/rails:8:in `require_relative'
from bin/rails:8:in `<main>'

所以我将 'require' 更新为 rails/commands/server/server_command 现在我得到了

rails s
/Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:110:in `<module:Command>': uninitialized constant Rails::Command::Base (NameError)
Did you mean? Base64
from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:109:in `<module:Rails>'
from /Users/aum/.rvm/gems/ruby-2.3.3@rails_app/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:11:in `<top (required)>'
from /Users/aum/rails_app/config/boot.rb:5:in `require'
from /Users/aum/rails_app/config/boot.rb:5:in `<top (required)>'
from bin/rails:8:in `require_relative'
from bin/rails:8:in `<main>'

我不确定如何/在何处指定 Rails 5.2.1 中的主机和端口,因为 default_options 定义也已在此处更改:https://github.com/rails/rails/blob/master/railties/lib/rails/commands/server/server_command.rb#L68

注意:我可以使用 rails s -b 0.0.0.0 -p 1234 启动服务器,但这不是我想要做的。

预先感谢您的帮助!

最佳答案

假设您使用的是 puma ,这是 Rails 5 的默认 HTTP 服务器,绑定(bind)选项在 config/puma.rb 中定义:

bind 'tcp://0.0.0.0:3000'

关于ruby-on-rails - 如何配置 Rails 5.2.1 服务器监听所有接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52785783/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com