Heroku RACK_ENV 表示“开发”薄,但“分期”关于独角兽

发布于 2024-11-28 08:53:13 字数 699 浏览 1 评论 0原文

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

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

heroku config:add RACK_ENV=staging --app appname

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

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

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

当我推送到 Heroku 并在 herokuapp.com 上点击相同的路线时,我得到了 development 而不是 staging

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

现在,当我到达路线时,我得到了预期的分段

还有其他人看过这个吗?我在另一个运行 Thin 的项目中的解决方法是从 New Relic 应用程序名称中删除环境。 (我没有切换到 Unicorn,因为我需要 New Relic 才能工作,并且目前 Cedar 和 New Relic 以及 Unicorn 一起工作)。

I came across this behavior and was wondering if anyone else had seen it. I have a workaround so it's not a show-stopper.

I created a new app on Heroku with a Cedar stack. When demonstrating multiple environments I added the following config var:

heroku config:add RACK_ENV=staging --app appname

I visually verified that the environment var was set, then put the following route in my simple Sinatra example:

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

When I tested locally on my laptop, I received the expected development.

When I pushed to Heroku and hit the same route on herokuapp.com I got development instead of staging.

I switched the web server from Thin to Unicorn through the Procfile and pushed the changes back up to Heroku.

Now when I hit the route, I get the expected staging.

Has anyone else seen this? My workaround on another project where I was running Thin was to key the environment off of the New Relic app name. (I didn't switch to Unicorn because I need New Relic to work and currently Cedar and New Relic and Unicorn work together).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅一夜美梦 2024-12-05 08:53:13

我使用heroku的示例sinatra应用程序在cedar堆栈上使用sinatra和thin时遇到了同样的问题。 RACK_ENV 拒绝设置为除开发之外的任何内容。 (Heroku 似乎认为 RACK_ENV 已设置,因为运行“heroku config”会显示您设置的环境,但在应用程序中它始终是开发环境)。

竹栈上的同一个应用程序没有任何问题。

编辑:我向heroku提交了一张关于此问题的票证,并得到了非常快速的回复,为我修复了错误:

引用:
如果您使用 Thin,我们的默认 Procfile 中似乎存在一个小错误。您可以创建一个包含以下内容的 Procfile 吗?

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

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

述情 2024-12-05 08:53:13

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

You can also set both your RACK_ENV and RAILS_ENV to staging using the Heroku gem ... then it works as expected. I think it may be a problem with Heroku.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文