5

我遇到了这种行为,想知道是否有其他人看到过。我有一个解决方法,所以它不是一个阻碍。

我在 Heroku 上使用 Cedar 堆栈创建了一个新应用程序。在演示多个环境时,我添加了以下配置变量:

heroku config:add RACK_ENV=staging --app appname

我直观地验证了环境变量是否已设置,然后将以下路由放入我的简单 Sinatra 示例中:

get '/?' do
  ENV['RACK_ENV']
end

当我在笔记本电脑上进行本地测试时,我收到了预期的development.

当我推到 Heroku 并在 herokuapp.com 上走同样的路线时,我得到developmentstaging.

我通过 Procfile 将 Web 服务器从 Thin 切换到 Unicorn,并将更改推送回 Heroku。

现在,当我到达路线时,我得到了预期的staging.

有没有其他人看过这个?我在另一个运行 Thin 的项目上的解决方法是将环境与 New Relic 应用程序名称分开。(我没有切换到 Unicorn,因为我需要 New Relic 才能工作,目前 Cedar 和 New Relic 和 Unicorn 一起工作)。

4

2 回答 2

14

I had the same problem with sinatra and thin on the cedar stack using heroku's example sinatra app. The RACK_ENV refuses to be set to anything but development. (Heroku seems to think that it's RACK_ENV is set, since running 'heroku config' displays the environment you set, however in the app it's always development).

The same app on the bamboo stack had no problems.

EDIT: I submitted a ticket to heroku about this and got a really quick response which fixed the bug for me:

QUOTE: It looks like there's a small bug in our default Procfile if you're using thin. Can you create a Procfile with the following in it?

web: bundle exec thin start -R config.ru -e $RACK_ENV -p $PORT

于 2011-10-29T00:14:31.637 回答
4

您还可以使用 Heroku gem 将 RACK_ENV 和 RAILS_ENV 设置为暂存......然后它按预期工作。我认为这可能是 Heroku 的问题。

于 2012-02-17T15:35:33.690 回答