1 00:00:00,750 --> 00:00:04,350 In the last section we put together a little bit of logic inside of our kids. 2 00:00:04,460 --> 00:00:11,180 As file to correctly figure out whether or not we are running our server inside of the production environment. 3 00:00:11,220 --> 00:00:17,550 So when we are running on her Oku this variable right here will be automatically set exactly equal to 4 00:00:17,550 --> 00:00:18,940 the string of production. 5 00:00:19,140 --> 00:00:22,940 So this is something that all happens automatically on Hoku for you. 6 00:00:23,400 --> 00:00:30,600 Now if we are on our own local machine like on our current lap top this environment variable will probably 7 00:00:30,600 --> 00:00:37,290 not be defined or at least should not be equal to production and so on our local machine we should always 8 00:00:37,290 --> 00:00:39,190 fall into the Elle's case down here. 9 00:00:39,480 --> 00:00:42,440 So right now let's first take care of this L's case. 10 00:00:42,450 --> 00:00:47,730 So we want to make sure that if we fall into this thing right here we export all of the code out of 11 00:00:47,730 --> 00:00:52,550 our dev J.S. file which is our development set of keys. 12 00:00:52,770 --> 00:00:59,690 So to do so on this line right here we are both going to export and require in the Devcon J.S. file 13 00:00:59,700 --> 00:01:01,100 at the same time. 14 00:01:01,170 --> 00:01:04,690 So I will first write some code that will require in the def file. 15 00:01:04,860 --> 00:01:12,840 So I will say require Dev and then I will immediately export it by setting that equal to module. 16 00:01:12,870 --> 00:01:16,500 Exports equals that require statement. 17 00:01:16,500 --> 00:01:22,230 So in other words just pull the dev set of keys in and immediately pass back to whoever's asking for 18 00:01:22,230 --> 00:01:25,440 this set of keys from this file right here. 19 00:01:25,440 --> 00:01:30,620 So now everywhere else inside of our application we shouldn't have to change any logic whatsoever. 20 00:01:30,810 --> 00:01:36,690 As far as all the other files in our application are concerned they can still require in the Keys not 21 00:01:36,690 --> 00:01:41,910 just file and get the right set of keys or at least for right now the development set which is good 22 00:01:41,910 --> 00:01:42,860 enough. 23 00:01:43,460 --> 00:01:43,740 OK. 24 00:01:43,770 --> 00:01:45,910 So that takes care of development. 25 00:01:45,930 --> 00:01:50,300 Now we are going to also take care of the production set of keys as well. 26 00:01:50,400 --> 00:01:55,940 So I'm going to create a new file called Prod. genius. 27 00:01:56,400 --> 00:01:58,260 And again I'm going to put a comment at the top. 28 00:01:58,290 --> 00:01:59,670 You do not have to do this. 29 00:01:59,670 --> 00:02:04,770 This is just for your benefit and to say this production please. 30 00:02:04,870 --> 00:02:08,910 You're not going to leave this empty for just a second. 31 00:02:08,910 --> 00:02:12,090 We'll come back in a moment and fill everything in here before we do. 32 00:02:12,100 --> 00:02:16,690 Let's take care of all the logic over here in the Keystone G-S file. 33 00:02:16,740 --> 00:02:22,530 So we're going to see essentially the same statement up in the first elf's case or if case excuse me 34 00:02:22,950 --> 00:02:24,090 up here as well. 35 00:02:24,570 --> 00:02:34,660 So if we are in production required in the Prod. file and then immediately assign it to module exports. 36 00:02:34,680 --> 00:02:35,020 Okay. 37 00:02:35,040 --> 00:02:36,170 So that's pretty much it. 38 00:02:38,500 --> 00:02:44,140 So last thing to do is put together our product JSE file and then make sure that we set up all of our 39 00:02:44,230 --> 00:02:46,520 environment variables on her Roku as well. 40 00:02:46,630 --> 00:02:49,340 So we're almost there just a little bit more. 41 00:02:49,540 --> 00:02:52,570 I do want to remind you that this is really a one time set up. 42 00:02:52,720 --> 00:02:55,800 Over time we're going to add in a couple of other keys as well. 43 00:02:55,870 --> 00:02:59,410 But it will or it will always be much faster than what we are currently doing. 44 00:02:59,530 --> 00:03:01,300 So just one time. 45 00:03:02,060 --> 00:03:04,670 So let's find our product just file. 46 00:03:04,690 --> 00:03:11,230 So we want to make sure that we export a object out of this thing where the values inside that object 47 00:03:11,290 --> 00:03:15,820 are being pulled from environment variables in the Heroku environment. 48 00:03:15,820 --> 00:03:18,320 So that's kind of confusing to say with words. 49 00:03:18,340 --> 00:03:20,500 In practice it will be pretty straightforward. 50 00:03:20,500 --> 00:03:25,120 And once we wire everything together I think you'll agree it's not the worst thing. 51 00:03:25,150 --> 00:03:30,290 So to get started I'm going to flip on over to the Keys just file. 52 00:03:30,490 --> 00:03:34,310 I'm going to select the entire statement inside of here. 53 00:03:34,470 --> 00:03:37,700 I'm going to copy it and paste it over here in prodcuts. 54 00:03:37,750 --> 00:03:38,760 Yes. 55 00:03:38,830 --> 00:03:40,590 Now we're not going to keep the same keys. 56 00:03:40,710 --> 00:03:45,880 I'm going to delete all the key is right now the only reason that I just copy pasted this was to make 57 00:03:45,880 --> 00:03:51,850 sure that we get all identical property names for this object because we still want to export the same 58 00:03:51,910 --> 00:03:53,090 properties here. 59 00:03:53,110 --> 00:03:58,580 The only difference is that the keys will be changed OK. 60 00:03:58,650 --> 00:04:03,770 And now when I see the file prettier is complaining because I've got a little typo in here. 61 00:04:03,800 --> 00:04:06,230 That's totally fine. 62 00:04:06,260 --> 00:04:06,580 OK. 63 00:04:06,590 --> 00:04:11,990 So now we are going to make sure that when ever this file is required in the production environment 64 00:04:12,020 --> 00:04:18,990 we're on Heroku the values for each of these keys are pulled from our Heroku environment variables. 65 00:04:19,010 --> 00:04:26,370 So for each one of these We're going to say process EMV and other words look at our environment variables. 66 00:04:26,960 --> 00:04:33,100 For the first one we're going to say find the environment variable called Google client ID. 67 00:04:33,140 --> 00:04:38,630 Now I want to tell you that by convention we usually list out environment variables with all capitals 68 00:04:38,930 --> 00:04:41,040 and then underscores between each word. 69 00:04:41,210 --> 00:04:44,230 So we're not going to say just google client id like this right here. 70 00:04:44,270 --> 00:04:47,640 Instead by convention we don't have to do this again. 71 00:04:47,660 --> 00:04:56,450 I can't say enough it's by convention we will say Google underscore client underscore ID and then we're 72 00:04:56,450 --> 00:05:00,220 going to essentially repeat the same process for everything else as well. 73 00:05:00,470 --> 00:05:01,640 So process. 74 00:05:01,770 --> 00:05:09,220 EMV dot Google client secret process. 75 00:05:09,260 --> 00:05:14,070 EMV dot Lango you or I process. 76 00:05:14,130 --> 00:05:17,120 Ian V dot cookie. 77 00:05:17,380 --> 00:05:19,820 Like so OK. 78 00:05:20,430 --> 00:05:21,860 So it's looking pretty good. 79 00:05:22,410 --> 00:05:25,440 So we are almost complete with editing our server here. 80 00:05:25,440 --> 00:05:31,350 There's just one last thing to do to make sure that we set up all of our version control correctly. 81 00:05:31,350 --> 00:05:35,640 So there's one little thing that I haven't quite made super clear. 82 00:05:35,640 --> 00:05:40,030 We have very clearly said that the dev J.S. file will not be committed. 83 00:05:40,080 --> 00:05:45,820 So we do not accidently push all of our development keys to her to get hovering like that. 84 00:05:45,900 --> 00:05:52,230 We said that we are now going to commit the keys just file so that no matter what our application will 85 00:05:52,320 --> 00:05:57,520 always be able to ask this file for all of the key for some set of keys. 86 00:05:57,780 --> 00:06:00,950 And now the very last thing this is kind of like the wild card. 87 00:06:01,210 --> 00:06:05,420 We're going to say that we are going to commit the product. 88 00:06:05,440 --> 00:06:09,670 JS file do commit fraud. 89 00:06:09,820 --> 00:06:10,900 Yes. 90 00:06:11,430 --> 00:06:18,090 And the reason for this is to make sure that when we push our project up to Heroku we do want to include 91 00:06:18,180 --> 00:06:20,680 that development that product js file. 92 00:06:20,760 --> 00:06:25,920 So the thing that says essentially hey just take all of the keys from environment variables. 93 00:06:26,310 --> 00:06:31,980 If we were to get ignore this file right here so if we did not commit it to source control when we pushed 94 00:06:31,980 --> 00:06:38,700 our project up to Roku and then our server started up it would hit our Keystone J.S. file it would say 95 00:06:38,700 --> 00:06:39,700 we are in production. 96 00:06:39,720 --> 00:06:45,210 So I want the broad set of keys and then if we didn't commit this file and didn't committed to Heroku 97 00:06:45,420 --> 00:06:50,640 this file wouldn't exist and boom we would just see a gigantic gigantic air which is obviously not what 98 00:06:50,640 --> 00:06:52,390 we want. 99 00:06:52,390 --> 00:06:52,740 OK. 100 00:06:52,770 --> 00:06:54,460 So that's pretty much it. 101 00:06:54,780 --> 00:07:05,270 We are going to change our Get Get ignore file just a little bit to better convey these facts here. 102 00:07:05,310 --> 00:07:10,750 So back inside of our code editor I'll find the DOT get ignore in our project directory. 103 00:07:11,010 --> 00:07:15,660 Remember anything that we add to this file will no longer be be committed to get. 104 00:07:15,690 --> 00:07:17,620 Whenever we do a commit. 105 00:07:17,670 --> 00:07:23,550 So rather than ignoring the keys not just file because I do want to include keys not just us. 106 00:07:23,670 --> 00:07:28,290 Now the only file that I want to ignore is dev J us instead. 107 00:07:28,380 --> 00:07:34,890 So dev J us like so and now in my code editor as a reminder it gives me some colors. 108 00:07:34,890 --> 00:07:39,840 Whenever my different files are ignored or have changes to them are like that. 109 00:07:39,840 --> 00:07:44,210 You can see that my def jazz file is now greyed out which means it will not be committed. 110 00:07:44,430 --> 00:07:46,320 But the key is not just in the product. 111 00:07:46,340 --> 00:07:49,580 Jazz files well so this is looking pretty good. 112 00:07:50,320 --> 00:07:56,430 OK so the last thing for us to do is flip over to Hoku and set up all these environment variables before 113 00:07:56,430 --> 00:07:57,000 we do that. 114 00:07:57,000 --> 00:08:02,220 Let's take a quick break come back and we'll take care of that last step of configuration on her Roku 115 00:08:02,490 --> 00:08:04,520 so I'll see you in just a second.