ruby-on-rails – 在Heroku的Sinatra应用程序中,会话不是通过Dynos共享的

这是有道理的.但是,这个问题的一些首选工作是什么?

解决方法

在我的评论中,我建议使用 rack cookie based sessions,但是考虑到这一点,Sinatra会话是Rack cookie会话.

进一步,我found this in the Sinatra docs

To improve security,the session data in the cookie is signed with a session secret. A random secret is generate for you by Sinatra. However,since this secret will change with every start of your application,you might want to set the secret yourself,so all your application instances share it:

set :session_secret,'super secret'

所以看来,每个Heroku dyno都生成一个不同的键,所以不能读每个对话的cookie,你需要指定一个键,所以每个dyno使用相同的键.

而不是为您的源代码添加秘密密钥,您可能更好地设置一个environment variable

$heroku config:add SESSION_KEY=a_longish_secret_key

然后在你的sinatra应用程序:

enable :sessions
set :session_secret,ENV['SESSION_KEY']

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...