具有 SSL 支持和 ruby-debug 的瘦 [英] Thin with SSL support and ruby-debug
问题描述
有谁知道用 Thin 同时运行 ruby 调试器和 SSL 的方法吗?
Does anyone know of a way to run the ruby debugger and SSL at the same time with Thin?
我在 Rails 3.0.10 中成功使用 Thin.
I've been using Thin successfully with Rails 3.0.10.
我使用 rails server --debugger
启动它,我可以调试我的代码.
I start it using rails server --debugger
, and I can debug my code.
最近,我还需要为我的应用程序添加 SSL 支持,我希望能够使用自签名证书在本地对其进行测试.
Recently, I have also needed to add SSL support to my application, and I'd like to be able to test it locally with a self-signed certificate.
不幸的是,我还没有找到在使用 rails server
时使用 SSL 支持启动 Thin 的方法.
Unfortunately, I have not found a way to start Thin with SSL support when using rails server
.
我可以使用以下方法成功启动 Thin with SSL 支持:
I can successfully start Thin with SSL support by using:
thin start --ssl --ssl-verify --ssl-key-file ssllocal/server.key
--ssl-cert-file ssllocal/server.crt
但是,我还没有找到使用 thin start
激活调试器的方法.
However, I have not found a way to activate the debugger using thin start
.
所以看起来我可以选择运行调试器(rails server
)或 SSL(thin start
),但不能同时运行.
So it seems like I have the choice of running the debugger (rails server
) or SSL (thin start
), but not both.
似乎可以通过修改 rails/script 文件(见此处).我尝试过这种方法,但没有成功.这是其中一种尝试:
It seems possible to get Webrick to run SSL using rails server
by modifying the rails/script file (see here). I experimented with this approach, but I have not had success. Here's one of the attempts:
#!/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"
require 'rack'
require 'thin'
module Rails
class Server
def default_options
super.merge({
:Port => 3000,
:environment => (ENV['RAILS_ENV'] || "development").dup,
:daemonize => false,
:debugger => false,
:pid => File.expand_path("tmp/pids/server.pid"),
:config => File.expand_path("config.ru"),
:SSLEnable => true
:ssl => true,
"ssl-verify" => true,
"ssl-key-file" => File.expand_path("ssllocal/server.key"),
"ssl-cert-file" => File.expand_path("ssllocal/server.crt")
})
end
end
end
require 'rails/commands'
注意:对于那些可能想知道的人,我在我的根应用程序目录下创建了一个ssllocal"目录,这就是我存储 ssl 密钥和证书的地方.
Note: for those who might be wondering, I created an 'ssllocal' directory off my root application directory, and that's where I store the ssl keys and certs.
推荐答案
您可以尝试在您的开发环境中自己安装调试器.
You could try just requiring the debugger yourself in your development environment.
在您的 Gemfile 中:
In your Gemfile:
if RUBY_VERSION =~ /^1.9/
gem "ruby-debug19", :group => :development
else
gem "ruby-debug", :group => :development
end
在你的 config/environments/development.rb 的配置块中:
And within the config block of your config/environments/development.rb:
require 'ruby-debug'
Debugger.start
这允许您将调试器语句放在代码中的任何位置.
This permits you to place the debugger statement anywhere in your code.
这篇关于具有 SSL 支持和 ruby-debug 的瘦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!