1
00:00:00,860 --> 00:00:05,570
We've now got two different ways of serving up all of our different Riak project files, we can either

2
00:00:05,570 --> 00:00:11,300
redirect a request or proxy the request over to a running reactor development server, or we can try

3
00:00:11,300 --> 00:00:15,350
to serve up all the production built files directly from our local client package.

4
00:00:16,040 --> 00:00:19,400
So let me give you a quick reminder on why we want these two different methods.

5
00:00:20,590 --> 00:00:25,870
OK, so first, if we are running our application locally on our machine and we are doing active development

6
00:00:25,870 --> 00:00:31,210
on it, then we definitely want to make sure that we use that proxy over to the local ReachOut development

7
00:00:31,210 --> 00:00:31,530
server.

8
00:00:31,960 --> 00:00:36,580
This is what is going to allow you and I to make changes to our react application and then see the updates

9
00:00:36,580 --> 00:00:38,020
on the fly inside of our browser.

10
00:00:39,440 --> 00:00:44,240
However, if we are running our Szalai on the user's machine, so in other words, if a user has installed

11
00:00:44,240 --> 00:00:49,190
our Seelie on their computer, then we want to make sure that we are instead serve up all of our built

12
00:00:49,190 --> 00:00:52,820
files from the bill directory inside of our local client project.

13
00:00:53,360 --> 00:00:55,850
So these are the two scenarios we really care about.

14
00:00:57,170 --> 00:01:02,630
So at some point in time, we need to decide which scenario we are in, are we doing active development

15
00:01:02,750 --> 00:01:04,940
or are we running on a user's machine?

16
00:01:05,780 --> 00:01:10,640
In addition, we need to decide upon when we are going to make that decision, or in other words, where

17
00:01:10,640 --> 00:01:14,330
inside of our code base are we going to decide between these two different options?

18
00:01:14,840 --> 00:01:16,640
Well, here's what I think we should probably do.

19
00:01:17,340 --> 00:01:21,950
I think that inside of our Seelie, we should place some logic inside there for deciding whether we

20
00:01:21,950 --> 00:01:27,260
are doing some development on our local machine or if we are running on a user's machine and essentially

21
00:01:27,260 --> 00:01:28,520
in a sort of production mode.

22
00:01:29,730 --> 00:01:31,980
So we should ask that question inside the Seelie.

23
00:01:32,950 --> 00:01:37,900
Then whenever we call the function from local API, we're going to pass down an additional argument

24
00:01:37,930 --> 00:01:41,590
that we're going to call use proxy, allow this be a very simple boolean.

25
00:01:41,590 --> 00:01:46,900
So either true or false and use proxy will be used to decide whether we're going to use the proxy or

26
00:01:46,900 --> 00:01:48,850
serve up files from that static directory.

27
00:01:50,240 --> 00:01:50,990
That's pretty much it.

28
00:01:52,210 --> 00:01:58,750
So back inside of my local API index file, I'm going to find my search function right here and I'm

29
00:01:58,750 --> 00:02:05,410
going to add in a fourth argument to this function that I will call use proxy, and that's going to

30
00:02:05,410 --> 00:02:06,190
be a boolean.

31
00:02:08,570 --> 00:02:12,440
I'm going to save this file right away because it's going to reformat this function quite a bit because

32
00:02:12,440 --> 00:02:13,850
that line is really long now.

33
00:02:16,000 --> 00:02:20,080
OK, so then inside of you, we're going to set up an if statement, we're going to say that if use

34
00:02:20,080 --> 00:02:23,100
proxy is true, we'll go ahead and set up our proxy middleware.

35
00:02:23,350 --> 00:02:26,080
Otherwise, we'll set up the express static middleware.

36
00:02:27,340 --> 00:02:31,330
So I'm going to add in down here if use proxy.

37
00:02:32,560 --> 00:02:39,010
Then let's go ahead and comment on the approximately where stuff cut it and paste it into the if statement.

38
00:02:40,430 --> 00:02:47,060
And then otherwise, so inside of our case, we'll take the other two lines at those and put them in

39
00:02:47,060 --> 00:02:47,600
like so.

40
00:02:51,050 --> 00:02:56,390
OK, so now it really comes down to how we're going to actually decide whether to use proxy is going

41
00:02:56,390 --> 00:02:57,710
to be true or false.

42
00:02:58,280 --> 00:03:01,970
So we have to go back over to our zeolite now and probably inside of our reserve command.

43
00:03:02,210 --> 00:03:07,370
We need to essentially answer this question, are we doing local development or are we running on a

44
00:03:07,370 --> 00:03:08,180
user's machine?

45
00:03:08,630 --> 00:03:11,030
Answering this question is going to be a little bit more challenging.

46
00:03:11,250 --> 00:03:13,700
So let's take a look at how we can answer that in the next video.

