gpt4 book ai didi

ruby-on-rails - 如何在开发中更改Rails 3服务器默认端口?

转载 作者:行者123 更新时间:2023-12-03 04:18:19 27 4
gpt4 key购买 nike

在我的开发机器上,我使用端口 10524。所以我这样启动我的服务器:

rails s -p 10524

有没有办法将默认端口更改为 10524,这样我就不必在每次启动服务器时附加端口?

最佳答案

首先 - 不要编辑 gem 路径中的任何内容!它会影响所有的项目,以后你会遇到很多问题......

在您的项目中按如下方式编辑script/rails:

#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)

# THIS IS NEW:
require "rails/commands/server"
module Rails
class Server
def default_options
super.merge({
:Port => 10524,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru")
})
end
end
end
# END OF CHANGE
require 'rails/commands'

原理很简单 - 您正在对服务器运行程序进行猴子修补 - 因此它只会影响一个项目。

更新:是的,我知道有更简单的解决方案,bash 脚本包含:

#!/bin/bash
rails server -p 10524

但是这个解决方案有一个严重的缺点 - 非常无聊。

关于ruby-on-rails - 如何在开发中更改Rails 3服务器默认端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3842818/

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