We are right in the middle of generating the production set of our API credentials for the Google API.
At this point we have to enter in our authorized javascript origin and our javascript authorized redirect
you or I in both cases the addresses that we put here are going to be different.
So you are not going to put in the same thing that I've put in.
We're going to put in slightly different addresses.
And that's because our respective Heroku applications are hosted on different domains.
So to figure out what domain or what address you should use in here I'm going to open up my terminal.
I'm going to find my running server.
I'm going to kill it and I'm going to run the command Heroku open.
This is going to open up a browser window at our running Heroku server.
So up in the address bar this is the address that you want to use for your authorized redirect.
So I'm going to select this address.
I will copy it and then flip back over.
Now to be a hundred percent clear you do not want to use the same address as me.
Like do not type in agile by you it will not work for you.
So make sure you use your own respective address.
Back over.
So let's do the authorized redirect you or I first remember this is the setting that says it is OK if
users get redirected from the Google off flow to this address.
So for us in the production world it will be our address right here.
Slash Auth. slash Google slash Colback like so.
And then for our authorized javascript origin This is where it is valid to send the user into the OT
flow from.
So in other words if we redirect our users from the address we put in here over to the Google flow then
that is valid and okay and Google is going to allow it.
So inside of here we're going to just put in the domain by itself and then make sure cause you're probably
going to paste it with a slash at the end.
Google this format here does not want to see that flash.
If you click out it's going to turn red and it's going to say cannot end with Flash.
So make sure you go in there and you delete that little slash on the end.
And now it's OK and good to go.
OK.
So that's pretty much it.
We will create our credentials by clicking create at the bottom and then we'll get this nice pop up
that shows us our new set of production credentials.
So we now have our production version of the Google API credentials and our production credentials for
our Mongo database.
OK.
So that's pretty much it on the resource generation side.
Now we're going to flip over to our actual code and set up our keys.
File to require in the correct set of credentials depending on whether or not we are running our server
in development or production.
So to be really clear about one change that we're going to make here that might not be entirely obvious.
Remember that right now all of our keys are in the Keys don't just file and we are not committing that
to source control right now.
And so moving forward we're going to change that.
We are going to make sure that we do in fact commit this file to source control.
We will commit it to get so that no matter what our application will always have something to at least
point to the right set of keys to use.
So keys to J.S. will no longer contain the actual keys.
It will just have some logic to decide what set to use.
Now we're not going to commit and use stuff down here.
It's just about making sure that we do not commit the set of keys.
All right so let's get to it.
Back in my code editor I'm going to find my config folder and then inside of there I'm going to make
my dev js file.
So dev J.S..
So this is where we're going to place all of our actual very real development API keys.
All of those keys are currently listed in the Keys G-S file.
So I'm going to cut everything out of us and paste it into depth now just to make sure that it's really
clear what file I'm in.
Because we're going to be jumping between a lot of files very quickly.
I'm going to put a little comment here at the top that says death.
J.S. don't commit this.
OK.
So you don't have to put this comments up here.
I just want you to have something as you're watching a video where you can easily say OK we're in Def
Jam right now.
Now back inside of keys yes I'm going to put a comment that says he's just yes and I'll say.
Figure out what set of credentials to return.
OK.
So in case you start G-S we have to put some logic to decide whether or not we are in a production or
development environment.
And so there might actually be a production or develop as I said.
So this might seem like something that's kind of hard to do.
You might be sitting there thinking like you know how in the world do we do this.
In reality it's actually pretty straightforward.
When you deploy your server to Heroku there is an existing environment variable called node underscore
EMV that environment very well tells us whether or not we are running in a production environment.
Now we have previously already used one production or one environment variable that is being set up
by Heroku back inside of our indexed file.
So if we go back over there and then we go to the very bottom of the file.
Remember we had previously read the port from the environment variables set up by Heroku.
So we're going to do the exact same thing decide whether or not we are in production because Heroku
is going to set up this other environment variable for us automatically as well.
So inside the key file we will say if process EMV dot node underscore EMV is equal to production then
we're going to say we are in production return the Prague's set of keys.
Else we are in development returned the dev keys OK.
So that's pretty much it.
So at this point let's take a quick break.
When we come back we're going to figure out exactly how we return the correct set of keys from both
these statements.
So quick break and I'll see you in the next section.