1

I uploaded a Sinatra app to the server (heroku). But it seems like the app acts itself like it's at a localhost unlike my another Rails app which works well there.

So how do I check if my Sinatra app uses the correct environment or not? And how does Sinatra know which environment to use?

Alexandre
  • 13,030
  • 35
  • 114
  • 173

2 Answers2

1

By nature heroku will take care of setting the environment. By default it's "production". In case you have different config/behavior for different use case, you would have to code that first.

For example

if ENV=="production"
  # do something
elsif ENV=="staging"
  # do something else
end

I am not sure why would you want to set environment explicitly to "production" or something else. That should be left at discretion of hosting environment.

Update

More info on Heroku documentation

Further update

 heroku run printenv

above should list environment variables.

ch4nd4n
  • 4,110
  • 2
  • 21
  • 43
0

I add an environment variable to all my heroku instances:

heroku config:add APP_NAME=<myappname>

Then, for Sinatra, I have the following in the config.ru:

# detect environments and setup some passwords
case ENV['APP_NAME'] 
  when 'prod-damon'
    # whatever for production
  when 'dev-damon'
    # whatever for development on Heroku
  else
    # whatever for local
end
Damon Mannion
  • 324
  • 2
  • 3