How do you run Rails with HTTPs locally for testing?

青春壹個敷衍的年華 提交于 2020-01-12 08:12:29

问题


Our dev envs use HTTP, prod uses HTTPS, this is causing issues that we can't reproduce locally with are HTTPS related.

How can I run rails with SSL locally for testing purposes? Is there a Webrick config?

Thanks


回答1:


you should to use thin to do it:

$ sudo apt-get install thin

And add this line in config/application.rb

config.force_ssl = true

Then run app on thin with command line:

$ thin start --ssl



回答2:


I think the question here is specific to the Rails 'testing' environment, which might mean rspec, and if so, this gist by jaikoo was what worked for me:

https://gist.github.com/jaikoo/daf88024b8de1cf9339b

With respect to the 'development' environment, ultimately I used thin, which I didn't really want to, but the best write-up of that I saw was this post by Keyur Gohil:

https://blog.botreetechnologies.com/enable-ssl-in-developement-using-thin-2a4bd1af500d

Though I put it in a batch file and added -D -V and made sure it ran on a different port:

#!
#  Sets up the use of SSL in development
#
# https://www.devmynd.com/blog/rails-local-development-https-using-self-signed-ssl-certificate/
#
bundle exec thin -D -V start -a localhost -p 3001 --ssl --ssl-key-file ~/development/apps/localhost_ssl_tsl_keys/localhost.key --ssl-cert-file ~/development/apps/localhost_ssl_tsl_keys/localhost.crt



回答3:


Ultimately, you should be running development without SSL, period. Unless something is wrong with your SSL Cert, you should not have errors that are independent of the different environments.

Staging is where you would test the SSL framework.



来源:https://stackoverflow.com/questions/8609240/how-do-you-run-rails-with-https-locally-for-testing

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