Now that we've made the determination of whether we are on the server or the browser we can now make
a request in either these statement cases and return some data from that request.
Remember the only thing that's really changing between these two cases is the domain that we are trying
to make the request to.
That's it going to handle the case in which we are on the browser first because that's just a little
bit easier to deal with so I'm gonna put inside of your bounced response is a wait axial stop get And
remember if we are on the browser we'll just make a request to the path that we're trying to access.
That is API users current user and the browser is going to automatically pretend in the domain for us.
So then after that we can return response data as a reminder of what we get back from the current user
request.
It's a response not data.
What that value actually is it's going to be an object that has a current user property that is null
at the user assigned out or an object.
If the user is signed in and that object allowed the idea email and so on we could shorten this up just
a little bit by doing a little bit of D structuring and only pulling out the data property because that's
the only thing we really care about here.
It's all a d structure our data and then only return data now I think would be great to do a quick test
of this right away.
So to test this out I'm gonna go back up to landing page so remember whatever we return right here is
going to show up as a prop in landing page and as we just saw data is going to be an object that has
the current user property so we should be able to access current user and I'll just do a console log
of current user.
Remember in order to execute get initial props on the browser we have to somehow get our application
to navigate over to this page.
So we're gonna go through that same sign up process which as we just discussed does cause good initial
props to be executed on the client so I'm going to go back over to my application I'm gonna navigate
to auth sign up I'll put in some email address and some password and sign up and sure enough after I
navigate over the request to current users issued and there's my data OK.
Well that definitely worked.
So now we're gonna repeat the same process with a case in which we are on the server.
So our code is going to look identical.
The only thing that's going to change is the domain that we are making the request to stop it in here.
Concept data is a way to access dot get and I'm gonna give myself a new line just because this URL is
going to end up being a little bit long.
So remember the format we use here it's going to be something like service name dot namespace dot S.V.
C cluster local.
So we need to go and look up these service name and the namespace that we want to make our requests
to get a quick reminder.
I'll go back over to my terminal.
I'm going to first print out all my different name spaces so QCT l get namespace.
So it's ingress engine X and I'll list out all the services inside that namespace.
So Cube Seitel get services bash n ingress engine X and that's the name of my service so we're going
to make our request to HDP coal and slash slash ingress dash and Gen-X then a dot ingress dash engine
X then dot as we see it cluster.
Local this will make our request over to ingress engine X but we don't really care about just making
a request to ingress engine x.
We specifically want to make one over two hour off service so we're still going to specify the route
at the very end of API users or into user.
So the first part right here at the domain is really just about reaching out to ingress engine X. The
route is about telling ingress engine X where we want our request to be forwarded onto OK.
So now that we've got the full domain on there I gotta tell you about one other very small technicality.
I'm gonna go back over to my ingress service file.
So here's our routing configuration.
You might recall that inside of here we specify these routing rules under a host of ticketing dot def
so whenever a request comes into ingress and connects ingress engine next needs to know about the host
that we are trying to reach are we trying to reach out to ticketing dot Dev.
We might also have some other set of rules for a totally different domain.
Now previously back inside the browser when we were making a request by navigating between different
pages or what have you.
The request was issued.
Included the domain that we were making a request from of ticketing dot Dev.
So when the request is coming from the browser engine X can easily inspect the request and understand
oh they're trying to access ticketing dot Dev.
No problem.
I will use this set of rules right here.
Unfortunately when we are making the request in this style there's nothing inside of here to indicate
what domain we are trying to access on ingress engine X ingress engine X is not going to assume that
we're using the only domain that's listed right here.
It's going to say I don't know what domain you're trying to access.
As a matter of fact let's do a quick test with this right now just to verify that it doesn't work because
we are not specifying the domain.
I'm going to complete this code.
I would still want to make sure that I return data.
I'm not going to say this and then again remember we want to make sure that we execute this stuff with
get initial props being executed on a server which means that we need to do a hard refresh of the page.
So I'll go back over I can do a hard refresh and I do in fact see a status code a forum for that 4 of
4 means that this request right here resulted in a forum for the request went out to ingress engine
X successfully but ingress engine X said hey sorry but I don't know what domain you're trying to access
so I don't know what set of rules to use.
So how do we fix this.
Well pretty simple as the second argument to axial stuck it I'm going to put in an options object so
zoom out for just a second so you can see that very easily and I'm going to include a header section
inside of here and I'm going to give it a host of ticketing not deaf to this header right here of hosts
that is going to be used by ingress engine X. It's going to take a look at out this header that's going
to say oh you were trying to get out the domain ticketing dock Dev.
Fantastic.
I got a set of routing rules for that it is right here and we're trying to access API users current
user.
No problem.
Send you off to the OTT service.
Let's now save this.
Look back over one more time I'm going to do another hard refresh to make sure that good initial promise
is executed on the server I'll then go over to my terminal and I will see up here you will probably
see an error but then down here towards the very bottom you should see no.
So what does no mean.
Well no means we were able to reach out to our art service correctly.
We reach out to that art service to fetch the current user.
We got back this current user object as data.
We returned it.
It showed up as a prop inside of landing page but our current user is showing up as No.
Why is it showing up at all.
Well remember right now we are not including any cookies.
Along with this request.
So even though the request is being issued over to our all service no cookies are being included just
as a quick reminder here we got a great diagram for it.
Where is it.
Here it is right here so our browser is making this request when you refresh the page and it is including
that cookie.
That is the initial page reload we do right there.
That request gets sent over to next.
Next then makes its own request over to ingress engine X but right now we are not including that cookie.
It cookie list.
So even though the request is going over to the all service your service is taking a look at this incoming
request it's saying you don't have a cookie.
Therefore you must be signed it so the point here is if we see no at or console.
That's actually really good.
It means the request was issued successfully.
We got it sent over.
All we have to do now is figure out how to take that cookie from the incoming request and attach it
onto the request that goes over ultimately to the auto service.
So we're almost there we're almost done.
One last quick video and we'll have this all solved.