How do I tell Sinatra what environment (development, test, production) it is?

穿精又带淫゛_ 提交于 2020-01-02 03:39:08

问题


(Disclaimer: New to deploying Sinatra on Heroku.)

I have seen http://www.sinatrarb.com/configuration.html and it tells me to set :environment, :production. My question is, how can I specify it to do: "when in Heroku, set environment as production, else stay in test/development."

Also, even after putting the line set :environment, :production, I don't think it is working because when I try to rackup the app locally, it's still running (when I know (or I think I know) that it shouldn't because I haven't installed postgres on my computer).

Gemfile

group :production do
  gem 'dm-postgres-adapter'
end

group :development, :test do
  gem 'dm-sqlite-adapter', "~> 1.2.0"
end

回答1:


The Sinatra environment has nothing to do with the gems inside the production group being loaded. These are separate and don't work with each other.

Sinatra takes the environment from the RACK_ENV environment variable, just start it with RACK_ENV=production rackup

Bundler works a bit different, you can choose which groups it should exclude when running bundle install: bundle install --without production




回答2:


Sinatra uses the APP_ENV environment variable. You can also set it explicitly via settings, as you mentioned.

A symbol specifying the deployment environment; typically set to one of :development, :test, or :production. The :environment defaults to the value of the APP_ENV environment variable (ENV['APP_ENV']), or :development when no APP_ENV environment variable is set.

That is how you tell Sinatra the environment.



来源:https://stackoverflow.com/questions/19420321/how-do-i-tell-sinatra-what-environment-development-test-production-it-is

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