I have my database set up in heroku and have created my Config Vars to hide my DB credentials. I believe this will all work when my app is deployed, but for development, I'm stuck with an application.properties that looks like :
spring.datasource.url=DB_URL
spring.datasource.username=DB_USERNAME
spring.datasource.password=DB_PASSWORD
Obviously, this will not work when I'm trying to test things.
How can I set it up so that the spring.datasources will have the proper configuration details when I'm developing and testing but then the config vars when pushed to Heroku?
If it helps to see where my head is at, I am used to working with dotenv with Node.js and looking for something similar for java.
Or am I going about this the wrong way? How can I set this up so it will work when deployed on heroku and when I am working on it locally?
Thanks!
Related
I'm trying to understand how I can hide API keys and still run my Heroku projects in the browser. I understand how I can add an environment variable within a .env file and then add the .env file to the .gitignore file which successfully hides the file containing the key from GitHub. However, when I try to push the latest commit from the remote repo in order to get the latest version of the project with Heroku, the hosted project does not work because it does not see the key that it needs to use.
Once I figure out how to get the hosted Heroku project to work with the latest GitHub commit that hides the key, I would like to figure out how to configure the key to only work with the domain of my project and not work with any other domain address since I know that it's still possible to find the key within the source code if it's not hidden using a backend server. I haven't gotten around to learning about backend so I would want to learn how to make the key only work with my domain. Thank you for any responses.
What you can do is set the API key as a config var in the settings section of your heroku dashboard by going to your heroku app, clicking on Settings and then scrolling down the config vars.
Alternatively, you can do this through the heroku cli with heroku config:set. Check out the heroku docs here on both of these options
Update: To access the config var, you use the same syntax as other environmental variables.
For example, if you set a configuration variable called API_KEY with the value being ABCDEFG, the way you'd access it in your code (with react):
var myKey = process.env.API_KEY;
I currently have a create-react-app deployed on my Heroku server, and I'm using the mars/create-react-app-buildpack.
I would like to be able to change the Heroku REACT_APP_ config variables on Heroku, and have them used in the React App.
Right now, they config variables are only picked up once when I call git push heroku master which means I need to redeploy for the config settings to change.
Has someone been able to find a workaround for this?
I found out this is already handled by #mars/create-react-app-buildpack with runtimes configuration variables.
You can use them in your react app as follows: https://github.com/mikehanssen/create-react-app-buildpack#runtime-configuration.
My app won't properly deploy or connect to my Mongo Atlas DB on Heroku. It keeps crashing. The heroku URL just says to do the logs, so here are the command line logs:
Here is what my server.js file looks like:
Here is what my config/keys looks like:
Here is what my keys_prod.js file looks like:
Here is what my keys_dev.js file looks like (redacted username and password), but this is what I have for my config vars in the heroku backend as well
Also took this screenshot, not sure if it matters though:
I didn't set the Heroku config vars correctly. I had set it to mongoURI like it was in the prod.keys JS folder instead of being MONGO_URI like I had declared it. In addition, I had to whitelist all of the ip's in Heroku's settings.
In deployment platforms like heroku, its hard to configure .env . i solved this in my project by using a npm package dotenv. Whatever file need process.env init,use this package
common require.js way :
require('dotenv').config()
its also got some cool options to manage env
here is the link
I'm developing an app (front-end app that consumes an API) based on the create-react-app package. I'm using Heroku to deploy and currently have two deployments based on the same codebase, staging and production. These deployments should use different development/staging/production APIs that have different databases.
Is it possible to tell create-react-app to use different env variables based on how I run react-scripts start?
env.development
REACT_API: https://localhost/react_api
env.staging
REACT_API: https://myappstagingapi.heroku.com
env.production
REACT_API: https://myappproductionapi.heroku.com
How would I do this? And is this a good workflow?
Thank you very much!
I had the similar situation having more environments than production and development while deployment was done automatically from Github.
First of all, make sure you are using the deployment buildpack i.e.
https://github.com/mars/create-react-app-buildpack.git
You can add this URL in Settings in your project on Heroku, replacing NodeJS default buildpack for instance.
Full documentation is here:
https://elements.heroku.com/buildpacks/nhutphuongit/create-react-app-buildpack
If you follow the link above, you can see the chapter Environment variables. So, in order that your React App can process custom variables:
Add a one that suits you with REACT_APP_ prefix to your Heroku project environment variables (through Settings in Heroku Dashboard) Note that only the envs with this prefix will be visible in your process.env later so you should amend your code accordingly
Redeploy the application.
This should make the things work. I am sure it is also possible to keep .env file but I prefer to have more control via Heroku Dashboard.
I'm new to web development and just finished Angular course at Coursera.
Everything was OK to my course project app until I have decided to deploy it at Cloud9. So the app doesn't have back-end and takes data from a simple db.json file which I was running on my computer with the json-server at localhost:3000.
I have cloned my git repo to the Cloud9, installed all dependencies and thought that the procedure with json-server will be the same and it will serve json data at the server, but it's looking that I was wrong.
I think I missed something and asking for explanation of my problem.
Thank you guys.
If you're looking to develop on Cloud9, you'll need to make sure you use process.env.IP instead of localhost and process.env.PORT (or port 8080) instead of 3000.
That being said, Cloud9 is not a hosting solution. If you use it as such, your account will be deactivated. Consider something like Heroku for deployment.