We've now got two different ways of serving up all of our different Riak project files, we can either
redirect a request or proxy the request over to a running reactor development server, or we can try
to serve up all the production built files directly from our local client package.
So let me give you a quick reminder on why we want these two different methods.
OK, so first, if we are running our application locally on our machine and we are doing active development
on it, then we definitely want to make sure that we use that proxy over to the local ReachOut development
server.
This is what is going to allow you and I to make changes to our react application and then see the updates
on the fly inside of our browser.
However, if we are running our Szalai on the user's machine, so in other words, if a user has installed
our Seelie on their computer, then we want to make sure that we are instead serve up all of our built
files from the bill directory inside of our local client project.
So these are the two scenarios we really care about.
So at some point in time, we need to decide which scenario we are in, are we doing active development
or are we running on a user's machine?
In addition, we need to decide upon when we are going to make that decision, or in other words, where
inside of our code base are we going to decide between these two different options?
Well, here's what I think we should probably do.
I think that inside of our Seelie, we should place some logic inside there for deciding whether we
are doing some development on our local machine or if we are running on a user's machine and essentially
in a sort of production mode.
So we should ask that question inside the Seelie.
Then whenever we call the function from local API, we're going to pass down an additional argument
that we're going to call use proxy, allow this be a very simple boolean.
So either true or false and use proxy will be used to decide whether we're going to use the proxy or
serve up files from that static directory.
That's pretty much it.
So back inside of my local API index file, I'm going to find my search function right here and I'm
going to add in a fourth argument to this function that I will call use proxy, and that's going to
be a boolean.
I'm going to save this file right away because it's going to reformat this function quite a bit because
that line is really long now.
OK, so then inside of you, we're going to set up an if statement, we're going to say that if use
proxy is true, we'll go ahead and set up our proxy middleware.
Otherwise, we'll set up the express static middleware.
So I'm going to add in down here if use proxy.
Then let's go ahead and comment on the approximately where stuff cut it and paste it into the if statement.
And then otherwise, so inside of our case, we'll take the other two lines at those and put them in
like so.
OK, so now it really comes down to how we're going to actually decide whether to use proxy is going
to be true or false.
So we have to go back over to our zeolite now and probably inside of our reserve command.
We need to essentially answer this question, are we doing local development or are we running on a
user's machine?
Answering this question is going to be a little bit more challenging.
So let's take a look at how we can answer that in the next video.