I've created a few different "environments" for my app that is hosted on heroku so I have: appName-staging.heroku.com appName-production.heroku.com
I want to use different google api keys for these applications, how do I do this? i've created a google.yml file that looks like:
development: api_key: 'ABCXYZ'
production: api_key: 'DEFXYZ'
so I use ABCSZY when developing locally, and DEFXYZ for appName-production.heroku.com question is, how do i get appName-staging.heroku.com to use a different key?
since every application deployed to Heroku is considered to be in "production", both appName-staging.heroku.com and appName-production.heroku.com use the same key.
You can view your Heroku API key by going to Account settings > API Key > Reveal .
You could add a heroku config variable to each environment, allowing you to identify each one from within the app.
Something along the lines of:
$ heroku config:add APP_NAME_ENV=production --app appName-production
$ heroku config:add APP_NAME_ENV=staging --app appName-staging
Then you could grab the current environment from within your app using:
ENV['APP_NAME_ENV']
And if you've got your YAML file as a hash called something like GOOGLE_KEYS
, the following would return the correct key for a given environment:
GOOGLE_KEYS[ENV['APP_NAME_ENV']]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With