1
00:00:02,000 --> 00:00:05,000
So, which implications does getServerSideProps

2
00:00:05,000 --> 00:00:09,000
running on the server only have for us?

3
00:00:09,000 --> 00:00:13,000
The implications can be found in this context object

4
00:00:13,000 --> 00:00:16,000
unlike context in getStaticProps

5
00:00:16,000 --> 00:00:19,000
we don't just have access to the params

6
00:00:19,000 --> 00:00:22,000
and a couple of other less important fields

7
00:00:22,000 --> 00:00:27,000
instead, we get access to the full request object as well.

8
00:00:27,000 --> 00:00:30,000
And also to the response which will be sent back

9
00:00:30,000 --> 00:00:32,000
so that we could even manipulate this

10
00:00:32,000 --> 00:00:36,000
and add extra headers if you wanted to.

11
00:00:36,000 --> 00:00:40,000
To be precise we do get a couple of values

12
00:00:40,000 --> 00:00:42,000
a couple of keys in this context object

13
00:00:42,000 --> 00:00:46,000
and we do get access still to the params

14
00:00:46,000 --> 00:00:49,000
that does not change if we have this on a dynamic page

15
00:00:49,000 --> 00:00:51,000
which we don't have here

16
00:00:51,000 --> 00:00:53,000
but if this would be on a dynamic page

17
00:00:53,000 --> 00:00:56,000
we still would get access to params

18
00:00:56,000 --> 00:00:59,000
but in addition, as mentioned, we also get access

19
00:00:59,000 --> 00:01:02,000
to the request object and the response object.

20
00:01:03,000 --> 00:01:06,000
Now, if you know a bit of Node.js

21
00:01:06,000 --> 00:01:08,000
and especially of Express.js

22
00:01:08,000 --> 00:01:10,000
this might look familiar to you.

23
00:01:10,000 --> 00:01:13,000
There you also can write server side code

24
00:01:13,000 --> 00:01:16,000
where you get a request object and the response object

25
00:01:16,000 --> 00:01:18,000
and you can then manipulate the response object

26
00:01:18,000 --> 00:01:21,000
as needed to send back an appropriate response.

27
00:01:22,000 --> 00:01:23,000
Now, you don't need to worry

28
00:01:23,000 --> 00:01:25,000
about sending back a response here

29
00:01:25,000 --> 00:01:28,000
Next.js will do that for you

30
00:01:28,000 --> 00:01:30,000
it will be derendered component

31
00:01:30,000 --> 00:01:32,000
but you can manipulate the response

32
00:01:32,000 --> 00:01:36,000
before it's sent back by adding extra headers, for example

33
00:01:36,000 --> 00:01:39,000
by adding a cookie, for example.

34
00:01:39,000 --> 00:01:42,000
In addition, you can also dive into the request object

35
00:01:42,000 --> 00:01:44,000
that reached the server

36
00:01:44,000 --> 00:01:47,000
and you can read incoming data from there.

37
00:01:47,000 --> 00:01:50,000
For example, headers that were attached through request

38
00:01:50,000 --> 00:01:54,000
and therefore cookie data that was attached to the request.

39
00:01:54,000 --> 00:01:56,000
Request and response the objects we're getting here

40
00:01:56,000 --> 00:02:01,000
are your official Node.js default incoming message

41
00:02:01,000 --> 00:02:03,000
and response objects.

42
00:02:03,000 --> 00:02:07,000
So, here I will briefly lock the request

43
00:02:07,000 --> 00:02:10,000
and then also lock the response

44
00:02:10,000 --> 00:02:14,000
so that we can get a closer look at them.

45
00:02:14,000 --> 00:02:19,000
If I save this and I reload user profile

46
00:02:19,000 --> 00:02:24,000
now this code executed again and now we see a long log here

47
00:02:24,000 --> 00:02:26,000
because these are quite complex objects

48
00:02:26,000 --> 00:02:30,000
with a lot of built in methods and properties.

49
00:02:30,000 --> 00:02:32,000
So, you'll see there's a lot in there

50
00:02:32,000 --> 00:02:35,000
and you definitely don't need to go through all of that.

51
00:02:35,000 --> 00:02:38,000
But for example, you see that there are headers in there

52
00:02:38,000 --> 00:02:41,000
which we could extract if we wanted to.

53
00:02:42,000 --> 00:02:43,000
Now, we don't need this here

54
00:02:43,000 --> 00:02:46,000
but it will become more important later

55
00:02:46,000 --> 00:02:48,000
once we talk about authentication.

56
00:02:48,000 --> 00:02:50,000
Now, I will quit this here and not go through all of that

57
00:02:50,000 --> 00:02:53,000
but you can definitely take a close look at that.

58
00:02:53,000 --> 00:02:57,000
And these again are the default node objects

59
00:02:57,000 --> 00:03:00,000
for incoming messages and for responses.

60
00:03:00,000 --> 00:03:03,000
And I'll link the documentation of these objects

61
00:03:03,000 --> 00:03:06,000
to this lecture so that you can take a closer look

62
00:03:06,000 --> 00:03:10,000
at what's in them in the official docs as well.

63
00:03:10,000 --> 00:03:12,000
And getting access to this kind of data

64
00:03:12,000 --> 00:03:15,000
can sometimes be important if you, again

65
00:03:15,000 --> 00:03:19,000
for example, needs special header or cookie data.

66
00:03:19,000 --> 00:03:21,000
And now another reason as mentioned before

67
00:03:21,000 --> 00:03:24,000
for using getServerSideProps could be

68
00:03:24,000 --> 00:03:27,000
that you don't need request or response specific data

69
00:03:27,000 --> 00:03:31,000
that you don't need to work with request or response

70
00:03:31,000 --> 00:03:34,000
but that you really wanna ensure that this function runs

71
00:03:34,000 --> 00:03:36,000
for every incoming request

72
00:03:36,000 --> 00:03:39,000
so that it's never static pre-generated.

73
00:03:39,000 --> 00:03:43,000
Because for example you have highly dynamic data

74
00:03:43,000 --> 00:03:46,000
which changes multiple times every second

75
00:03:46,000 --> 00:03:48,000
and therefore, you know, that any old page

76
00:03:48,000 --> 00:03:52,000
you would be serving would already be outdated.

77
00:03:52,000 --> 00:03:55,000
That could be another reason for using getServiceSideProps

78
00:03:56,000 --> 00:03:58,000
but as you see using it is simple.

79
00:03:58,000 --> 00:04:01,000
You can still write any server side code in there.

80
00:04:01,000 --> 00:04:05,000
You can still reach out to the dummy-backend.json file

81
00:04:05,000 --> 00:04:07,000
as we did it before, for example

82
00:04:07,000 --> 00:04:09,000
and you still return the props

83
00:04:09,000 --> 00:04:11,000
for the component function at the end.

84
00:04:11,000 --> 00:04:13,000
The only key difference is the kind of data

85
00:04:13,000 --> 00:04:15,000
you get access to in the context

86
00:04:15,000 --> 00:04:18,000
and the timing of this function.

