我需要在config / boot.rb文件中配置服务器端口。查看lib / rails / commands / server / server_command.rb,我们有:
125 def perform
126 set_application_directory!
127 Rails::Server.new(server_options).tap do |server|
128 # Require application after server sets environment to propagate
129 # the --environment option.
130 require APP_PATH
131 Dir.chdir(Rails.application.root)
132 server.start
133 end
134 end
135
136 no_commands do
137 def server_options
138 {
139 user_supplied_options: user_supplied_options,
140 server: @server,
141 log_stdout: @log_stdout,
142 Port: port,
143 Host: host,
144 DoNotReverseLookup: true,
145 config: options[:config],
146 environment: environment,
147 daemonize: options[:daemon],
148 pid: pid,
149 caching: options["dev-caching"],
150 restart_cmd: restart_command
151 }
152 end
153 end
如何从config / boot.rb配置端口呢? 提前谢谢。
答案 0 :(得分:0)
我也尝试过修补boot.rb来改变端口,但没有运气。在浏览时我了解到Rails 5附带了puma,它在config / puma.rb中配置。您可以更改该文件中的默认端口号,或者在启动rails之前通过设置PORT环境变量来覆盖它。
config/puma.rb
# Specifies the `port` that Puma will listen on to receive requests;
# default is 3000.
port ENV.fetch("PORT") { 3000 }
我希望这会有所帮助。