How do you handle SSL in development?

北慕城南 提交于 2019-12-04 08:16:45

问题


I have an application that uses HTTPS for some of its routes in conjunction with the ssl_requirement plugin. It's deployed and is working fine in production.

The question is how best to handle this in development, because at the moment I'm simply hacking my routes.rb to remove the :requirements key and obviously that's not very convenient or elegant:

map.resource :session, :controller => 'session',
                       :only => [:new, :create, :destroy],
                       :requirements => { :protocol => 'https' }

Ideally I'd like to be able to run the secure parts of my application in development on Mongrel without any changes. How can I achieve this? I'm using Mac OS X.


回答1:


Don't worry about SSL in development

For a development environment, IMO, you don't need to run SSL. It's not worth the time or hassle, especially as more people join the team. With regards to your routes, I would simply keep the protocol as http in the development environment:

protocol = Rails.env.development? ? "http" : "https"

map.resource :session, :controller => 'session',
                       :only => [:new, :create, :destroy],
                       :requirements => { :protocol => protocol }

Now, where you do need to test your SSL integration is on your staging environment -- the place where you deploy to just prior to deploying to production. This is where you want to accurately replicate your production environment. Your development environment does not need to match your production environment in this same way.




回答2:


As your rails apps get more complicated and you want to use advanced features like SSL your best bet is to switch to a development environment which more closely matches your production environment. This will allow you to create your own SSL certs and test in a way which will mirror the way your users will use your application.

I suggest moving to the same webserver as you use in production, which you've mentioned is apache/passenger.

In a related question... how do you manage your test environment with ssl? For this I'm currently hacking up my routes as you're doing. Is there a better way?



来源:https://stackoverflow.com/questions/2118685/how-do-you-handle-ssl-in-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!