In the last section we put together a little bit of logic inside of our kids.
As file to correctly figure out whether or not we are running our server inside of the production environment.
So when we are running on her Oku this variable right here will be automatically set exactly equal to
the string of production.
So this is something that all happens automatically on Hoku for you.
Now if we are on our own local machine like on our current lap top this environment variable will probably
not be defined or at least should not be equal to production and so on our local machine we should always
fall into the Elle's case down here.
So right now let's first take care of this L's case.
So we want to make sure that if we fall into this thing right here we export all of the code out of
our dev J.S. file which is our development set of keys.
So to do so on this line right here we are both going to export and require in the Devcon J.S. file
at the same time.
So I will first write some code that will require in the def file.
So I will say require Dev and then I will immediately export it by setting that equal to module.
Exports equals that require statement.
So in other words just pull the dev set of keys in and immediately pass back to whoever's asking for
this set of keys from this file right here.
So now everywhere else inside of our application we shouldn't have to change any logic whatsoever.
As far as all the other files in our application are concerned they can still require in the Keys not
just file and get the right set of keys or at least for right now the development set which is good
enough.
OK.
So that takes care of development.
Now we are going to also take care of the production set of keys as well.
So I'm going to create a new file called Prod. genius.
And again I'm going to put a comment at the top.
You do not have to do this.
This is just for your benefit and to say this production please.
You're not going to leave this empty for just a second.
We'll come back in a moment and fill everything in here before we do.
Let's take care of all the logic over here in the Keystone G-S file.
So we're going to see essentially the same statement up in the first elf's case or if case excuse me
up here as well.
So if we are in production required in the Prod. file and then immediately assign it to module exports.
Okay.
So that's pretty much it.
So last thing to do is put together our product JSE file and then make sure that we set up all of our
environment variables on her Roku as well.
So we're almost there just a little bit more.
I do want to remind you that this is really a one time set up.
Over time we're going to add in a couple of other keys as well.
But it will or it will always be much faster than what we are currently doing.
So just one time.
So let's find our product just file.
So we want to make sure that we export a object out of this thing where the values inside that object
are being pulled from environment variables in the Heroku environment.
So that's kind of confusing to say with words.
In practice it will be pretty straightforward.
And once we wire everything together I think you'll agree it's not the worst thing.
So to get started I'm going to flip on over to the Keys just file.
I'm going to select the entire statement inside of here.
I'm going to copy it and paste it over here in prodcuts.
Yes.
Now we're not going to keep the same keys.
I'm going to delete all the key is right now the only reason that I just copy pasted this was to make
sure that we get all identical property names for this object because we still want to export the same
properties here.
The only difference is that the keys will be changed OK.
And now when I see the file prettier is complaining because I've got a little typo in here.
That's totally fine.
OK.
So now we are going to make sure that when ever this file is required in the production environment
we're on Heroku the values for each of these keys are pulled from our Heroku environment variables.
So for each one of these We're going to say process EMV and other words look at our environment variables.
For the first one we're going to say find the environment variable called Google client ID.
Now I want to tell you that by convention we usually list out environment variables with all capitals
and then underscores between each word.
So we're not going to say just google client id like this right here.
Instead by convention we don't have to do this again.
I can't say enough it's by convention we will say Google underscore client underscore ID and then we're
going to essentially repeat the same process for everything else as well.
So process.
EMV dot Google client secret process.
EMV dot Lango you or I process.
Ian V dot cookie.
Like so OK.
So it's looking pretty good.
So we are almost complete with editing our server here.
There's just one last thing to do to make sure that we set up all of our version control correctly.
So there's one little thing that I haven't quite made super clear.
We have very clearly said that the dev J.S. file will not be committed.
So we do not accidently push all of our development keys to her to get hovering like that.
We said that we are now going to commit the keys just file so that no matter what our application will
always be able to ask this file for all of the key for some set of keys.
And now the very last thing this is kind of like the wild card.
We're going to say that we are going to commit the product.
JS file do commit fraud.
Yes.
And the reason for this is to make sure that when we push our project up to Heroku we do want to include
that development that product js file.
So the thing that says essentially hey just take all of the keys from environment variables.
If we were to get ignore this file right here so if we did not commit it to source control when we pushed
our project up to Roku and then our server started up it would hit our Keystone J.S. file it would say
we are in production.
So I want the broad set of keys and then if we didn't commit this file and didn't committed to Heroku
this file wouldn't exist and boom we would just see a gigantic gigantic air which is obviously not what
we want.
OK.
So that's pretty much it.
We are going to change our Get Get ignore file just a little bit to better convey these facts here.
So back inside of our code editor I'll find the DOT get ignore in our project directory.
Remember anything that we add to this file will no longer be be committed to get.
Whenever we do a commit.
So rather than ignoring the keys not just file because I do want to include keys not just us.
Now the only file that I want to ignore is dev J us instead.
So dev J us like so and now in my code editor as a reminder it gives me some colors.
Whenever my different files are ignored or have changes to them are like that.
You can see that my def jazz file is now greyed out which means it will not be committed.
But the key is not just in the product.
Jazz files well so this is looking pretty good.
OK so the last thing for us to do is flip over to Hoku and set up all these environment variables before
we do that.
Let's take a quick break come back and we'll take care of that last step of configuration on her Roku
so I'll see you in just a second.