Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

(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
like image 322
Daryll Santos Avatar asked Oct 17 '13 07:10

Daryll Santos


2 Answers

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

like image 106
chdorner Avatar answered Oct 19 '22 12:10

chdorner


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.

like image 25
Vinicius Brasil Avatar answered Oct 19 '22 11:10

Vinicius Brasil