ruby-on-rails – 具有SSL支持和ruby-debug的瘦身

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 具有SSL支持和ruby-debug的瘦身前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有人知道使用Thin同时运行ruby调试器和SSL的方法

我一直在使用Rails 3.0.10成功使用Thin.

我使用rails server –debugger启动它,我可以调试我的代码.

最近,我还需要为我的应用程序添加SSL支持,并且我希望能够使用自签名证书在本地测试它.

不幸的是,在使用rails服务器时,我还没有找到一种方法来启动Thin with SSL支持.

我可以使用以下方法成功启动Thin with SSL支持

  1. thin start --ssl --ssl-verify --ssl-key-file ssllocal/server.key
  2. --ssl-cert-file ssllocal/server.crt

但是,我还没有找到使用瘦启动激活调试器的方法.

所以我似乎可以选择运行调试器(rails服务器)或SSL(瘦启动),但不能同时运行.

通过修改rails / script文件(see here),似乎可以让Webrick使用rails服务器运行SSL.我尝试了这种方法,但我没有成功.这是尝试之一:

  1. #!/usr/bin/env ruby
  2. # This command will automatically be run when you run "rails" with Rails 3
  3. # gems installed from the root of your application.
  4.  
  5. APP_PATH = File.expand_path('../../config/application',__FILE__)
  6. require File.expand_path('../../config/boot',__FILE__)
  7.  
  8.  
  9. # THIS IS NEW:
  10. require "rails/commands/server"
  11. require 'rack'
  12. require 'thin'
  13. module Rails
  14. class Server
  15. def default_options
  16. super.merge({
  17. :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
  18. :ssl => true,"ssl-verify" => true,"ssl-key-file" => File.expand_path("ssllocal/server.key"),"ssl-cert-file" => File.expand_path("ssllocal/server.crt")
  19. })
  20. end
  21. end
  22. end
  23.  
  24.  
  25. require 'rails/commands'

注意:对于那些可能想知道的人,我在我的根应用程序目录下创建了一个’ssllocal’目录,这就是我存储ssl密钥和证书的地方.

解决方法

您可以尝试在开发环境中自己要求调试器.

在你的Gemfile中:

  1. if RUBY_VERSION =~ /^1.9/
  2. gem "ruby-debug19",:group => :development
  3. else
  4. gem "ruby-debug",:group => :development
  5. end

在config / environments / development.rb的config块中:

  1. require 'ruby-debug'
  2. Debugger.start

这允许您将调试器语句放在代码中的任何位置.

猜你在找的Ruby相关文章