1 00:00:01,450 --> 00:00:05,710 Now that we've made the determination of whether we are on the server or the browser we can now make 2 00:00:05,710 --> 00:00:10,740 a request in either these statement cases and return some data from that request. 3 00:00:10,750 --> 00:00:15,010 Remember the only thing that's really changing between these two cases is the domain that we are trying 4 00:00:15,010 --> 00:00:16,180 to make the request to. 5 00:00:16,180 --> 00:00:20,870 That's it going to handle the case in which we are on the browser first because that's just a little 6 00:00:20,870 --> 00:00:29,350 bit easier to deal with so I'm gonna put inside of your bounced response is a wait axial stop get And 7 00:00:29,350 --> 00:00:33,760 remember if we are on the browser we'll just make a request to the path that we're trying to access. 8 00:00:33,760 --> 00:00:41,460 That is API users current user and the browser is going to automatically pretend in the domain for us. 9 00:00:41,570 --> 00:00:47,900 So then after that we can return response data as a reminder of what we get back from the current user 10 00:00:47,900 --> 00:00:48,830 request. 11 00:00:48,920 --> 00:00:49,850 It's a response not data. 12 00:00:49,850 --> 00:00:55,020 What that value actually is it's going to be an object that has a current user property that is null 13 00:00:55,050 --> 00:00:57,940 at the user assigned out or an object. 14 00:00:57,950 --> 00:01:03,360 If the user is signed in and that object allowed the idea email and so on we could shorten this up just 15 00:01:03,370 --> 00:01:07,650 a little bit by doing a little bit of D structuring and only pulling out the data property because that's 16 00:01:07,650 --> 00:01:09,420 the only thing we really care about here. 17 00:01:09,450 --> 00:01:17,010 It's all a d structure our data and then only return data now I think would be great to do a quick test 18 00:01:17,010 --> 00:01:18,300 of this right away. 19 00:01:18,510 --> 00:01:23,880 So to test this out I'm gonna go back up to landing page so remember whatever we return right here is 20 00:01:23,880 --> 00:01:29,910 going to show up as a prop in landing page and as we just saw data is going to be an object that has 21 00:01:29,910 --> 00:01:35,520 the current user property so we should be able to access current user and I'll just do a console log 22 00:01:35,670 --> 00:01:39,120 of current user. 23 00:01:39,490 --> 00:01:45,280 Remember in order to execute get initial props on the browser we have to somehow get our application 24 00:01:45,280 --> 00:01:47,740 to navigate over to this page. 25 00:01:47,740 --> 00:01:54,140 So we're gonna go through that same sign up process which as we just discussed does cause good initial 26 00:01:54,140 --> 00:02:00,920 props to be executed on the client so I'm going to go back over to my application I'm gonna navigate 27 00:02:00,920 --> 00:02:08,450 to auth sign up I'll put in some email address and some password and sign up and sure enough after I 28 00:02:08,450 --> 00:02:14,720 navigate over the request to current users issued and there's my data OK. 29 00:02:14,750 --> 00:02:16,160 Well that definitely worked. 30 00:02:16,160 --> 00:02:20,240 So now we're gonna repeat the same process with a case in which we are on the server. 31 00:02:20,240 --> 00:02:21,830 So our code is going to look identical. 32 00:02:21,830 --> 00:02:27,680 The only thing that's going to change is the domain that we are making the request to stop it in here. 33 00:02:27,680 --> 00:02:33,870 Concept data is a way to access dot get and I'm gonna give myself a new line just because this URL is 34 00:02:33,870 --> 00:02:35,920 going to end up being a little bit long. 35 00:02:36,030 --> 00:02:44,750 So remember the format we use here it's going to be something like service name dot namespace dot S.V. 36 00:02:44,820 --> 00:02:46,900 C cluster local. 37 00:02:46,950 --> 00:02:51,300 So we need to go and look up these service name and the namespace that we want to make our requests 38 00:02:51,300 --> 00:02:53,900 to get a quick reminder. 39 00:02:53,900 --> 00:02:55,970 I'll go back over to my terminal. 40 00:02:55,970 --> 00:03:01,910 I'm going to first print out all my different name spaces so QCT l get namespace. 41 00:03:02,120 --> 00:03:06,380 So it's ingress engine X and I'll list out all the services inside that namespace. 42 00:03:06,410 --> 00:03:15,810 So Cube Seitel get services bash n ingress engine X and that's the name of my service so we're going 43 00:03:15,810 --> 00:03:24,450 to make our request to HDP coal and slash slash ingress dash and Gen-X then a dot ingress dash engine 44 00:03:24,450 --> 00:03:27,320 X then dot as we see it cluster. 45 00:03:27,330 --> 00:03:34,140 Local this will make our request over to ingress engine X but we don't really care about just making 46 00:03:34,170 --> 00:03:35,700 a request to ingress engine x. 47 00:03:35,730 --> 00:03:40,740 We specifically want to make one over two hour off service so we're still going to specify the route 48 00:03:40,770 --> 00:03:45,170 at the very end of API users or into user. 49 00:03:45,300 --> 00:03:50,070 So the first part right here at the domain is really just about reaching out to ingress engine X. The 50 00:03:50,070 --> 00:03:57,090 route is about telling ingress engine X where we want our request to be forwarded onto OK. 51 00:03:57,190 --> 00:04:02,830 So now that we've got the full domain on there I gotta tell you about one other very small technicality. 52 00:04:02,920 --> 00:04:05,560 I'm gonna go back over to my ingress service file. 53 00:04:05,830 --> 00:04:07,960 So here's our routing configuration. 54 00:04:08,170 --> 00:04:14,470 You might recall that inside of here we specify these routing rules under a host of ticketing dot def 55 00:04:15,600 --> 00:04:20,560 so whenever a request comes into ingress and connects ingress engine next needs to know about the host 56 00:04:20,580 --> 00:04:23,820 that we are trying to reach are we trying to reach out to ticketing dot Dev. 57 00:04:23,820 --> 00:04:27,650 We might also have some other set of rules for a totally different domain. 58 00:04:27,810 --> 00:04:33,600 Now previously back inside the browser when we were making a request by navigating between different 59 00:04:33,600 --> 00:04:35,200 pages or what have you. 60 00:04:35,250 --> 00:04:36,420 The request was issued. 61 00:04:36,420 --> 00:04:41,130 Included the domain that we were making a request from of ticketing dot Dev. 62 00:04:41,130 --> 00:04:46,200 So when the request is coming from the browser engine X can easily inspect the request and understand 63 00:04:46,470 --> 00:04:48,720 oh they're trying to access ticketing dot Dev. 64 00:04:48,720 --> 00:04:49,500 No problem. 65 00:04:49,540 --> 00:04:51,710 I will use this set of rules right here. 66 00:04:52,700 --> 00:04:57,770 Unfortunately when we are making the request in this style there's nothing inside of here to indicate 67 00:04:57,800 --> 00:05:04,280 what domain we are trying to access on ingress engine X ingress engine X is not going to assume that 68 00:05:04,280 --> 00:05:06,470 we're using the only domain that's listed right here. 69 00:05:06,560 --> 00:05:09,580 It's going to say I don't know what domain you're trying to access. 70 00:05:09,710 --> 00:05:14,420 As a matter of fact let's do a quick test with this right now just to verify that it doesn't work because 71 00:05:14,420 --> 00:05:16,520 we are not specifying the domain. 72 00:05:16,520 --> 00:05:18,010 I'm going to complete this code. 73 00:05:18,020 --> 00:05:20,410 I would still want to make sure that I return data. 74 00:05:20,510 --> 00:05:25,790 I'm not going to say this and then again remember we want to make sure that we execute this stuff with 75 00:05:25,880 --> 00:05:30,680 get initial props being executed on a server which means that we need to do a hard refresh of the page. 76 00:05:31,250 --> 00:05:37,710 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 77 00:05:37,700 --> 00:05:44,140 4 means that this request right here resulted in a forum for the request went out to ingress engine 78 00:05:44,140 --> 00:05:49,810 X successfully but ingress engine X said hey sorry but I don't know what domain you're trying to access 79 00:05:50,020 --> 00:05:52,570 so I don't know what set of rules to use. 80 00:05:52,750 --> 00:05:53,790 So how do we fix this. 81 00:05:53,800 --> 00:06:01,200 Well pretty simple as the second argument to axial stuck it I'm going to put in an options object so 82 00:06:01,210 --> 00:06:07,450 zoom out for just a second so you can see that very easily and I'm going to include a header section 83 00:06:07,450 --> 00:06:14,530 inside of here and I'm going to give it a host of ticketing not deaf to this header right here of hosts 84 00:06:14,680 --> 00:06:19,380 that is going to be used by ingress engine X. It's going to take a look at out this header that's going 85 00:06:19,380 --> 00:06:23,030 to say oh you were trying to get out the domain ticketing dock Dev. 86 00:06:23,230 --> 00:06:23,950 Fantastic. 87 00:06:23,950 --> 00:06:29,910 I got a set of routing rules for that it is right here and we're trying to access API users current 88 00:06:29,910 --> 00:06:30,260 user. 89 00:06:30,270 --> 00:06:30,840 No problem. 90 00:06:30,840 --> 00:06:33,490 Send you off to the OTT service. 91 00:06:33,570 --> 00:06:34,880 Let's now save this. 92 00:06:35,230 --> 00:06:41,960 Look back over one more time I'm going to do another hard refresh to make sure that good initial promise 93 00:06:41,960 --> 00:06:48,580 is executed on the server I'll then go over to my terminal and I will see up here you will probably 94 00:06:48,580 --> 00:06:53,200 see an error but then down here towards the very bottom you should see no. 95 00:06:53,230 --> 00:06:55,770 So what does no mean. 96 00:06:55,840 --> 00:06:59,780 Well no means we were able to reach out to our art service correctly. 97 00:06:59,830 --> 00:07:02,830 We reach out to that art service to fetch the current user. 98 00:07:02,860 --> 00:07:07,030 We got back this current user object as data. 99 00:07:07,030 --> 00:07:07,700 We returned it. 100 00:07:07,720 --> 00:07:13,580 It showed up as a prop inside of landing page but our current user is showing up as No. 101 00:07:13,750 --> 00:07:15,130 Why is it showing up at all. 102 00:07:15,140 --> 00:07:18,250 Well remember right now we are not including any cookies. 103 00:07:18,250 --> 00:07:19,750 Along with this request. 104 00:07:19,750 --> 00:07:26,480 So even though the request is being issued over to our all service no cookies are being included just 105 00:07:26,480 --> 00:07:29,270 as a quick reminder here we got a great diagram for it. 106 00:07:29,340 --> 00:07:30,110 Where is it. 107 00:07:30,110 --> 00:07:30,770 Where is it. 108 00:07:30,770 --> 00:07:31,520 Where is it. 109 00:07:31,520 --> 00:07:38,120 Here it is right here so our browser is making this request when you refresh the page and it is including 110 00:07:38,120 --> 00:07:38,710 that cookie. 111 00:07:38,750 --> 00:07:41,530 That is the initial page reload we do right there. 112 00:07:41,570 --> 00:07:43,520 That request gets sent over to next. 113 00:07:43,520 --> 00:07:49,320 Next then makes its own request over to ingress engine X but right now we are not including that cookie. 114 00:07:49,320 --> 00:07:50,660 It cookie list. 115 00:07:50,870 --> 00:07:55,400 So even though the request is going over to the all service your service is taking a look at this incoming 116 00:07:55,400 --> 00:07:57,320 request it's saying you don't have a cookie. 117 00:07:57,350 --> 00:08:04,310 Therefore you must be signed it so the point here is if we see no at or console. 118 00:08:04,310 --> 00:08:05,700 That's actually really good. 119 00:08:05,720 --> 00:08:07,880 It means the request was issued successfully. 120 00:08:07,880 --> 00:08:09,140 We got it sent over. 121 00:08:09,140 --> 00:08:13,850 All we have to do now is figure out how to take that cookie from the incoming request and attach it 122 00:08:13,880 --> 00:08:17,560 onto the request that goes over ultimately to the auto service. 123 00:08:17,600 --> 00:08:19,760 So we're almost there we're almost done. 124 00:08:19,760 --> 00:08:21,920 One last quick video and we'll have this all solved.