Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:02,390 --> 00:00:04,310
So it is time to deploy
2
00:00:04,310 --> 00:00:08,270
and we have two deployment options here, as we learned.
3
00:00:08,270 --> 00:00:10,810
Now, only the standard build makes sense
4
00:00:10,810 --> 00:00:13,240
for our project here at the moment,
5
00:00:13,240 --> 00:00:16,170
because we are using server-side features,
6
00:00:16,170 --> 00:00:19,583
like API routes or page re-validations,
7
00:00:20,550 --> 00:00:24,660
and therefore, I will now, again, run npm run build
8
00:00:24,660 --> 00:00:27,053
to produce this production output,
9
00:00:28,130 --> 00:00:31,190
even though we just did it, but still I'll now do that,
10
00:00:31,190 --> 00:00:36,010
and now that gives us the .next folder.
11
00:00:36,010 --> 00:00:40,000
That next folder contains this production output.
12
00:00:40,000 --> 00:00:44,650
Now, how would we deploy our page done in the end?
13
00:00:44,650 --> 00:00:48,140
Well, in the end, you can take your entire project folder
14
00:00:48,140 --> 00:00:51,410
and just move that onto a node JS server.
15
00:00:51,410 --> 00:00:56,220
So onto some remote computer that supports node JS,
16
00:00:56,220 --> 00:00:59,720
and then on that machine, you would run npm install
17
00:00:59,720 --> 00:01:01,740
to install all the dependencies again,
18
00:01:01,740 --> 00:01:04,900
and then npm start.
19
00:01:04,900 --> 00:01:07,490
Npm start runs next start,
20
00:01:07,490 --> 00:01:10,360
and that will then use that build output
21
00:01:10,360 --> 00:01:12,770
and bring up the production server.
22
00:01:12,770 --> 00:01:16,270
So npm start brings up the production server,
23
00:01:16,270 --> 00:01:19,000
and we can test this locally here.
24
00:01:19,000 --> 00:01:21,830
If I run npm start, I'm now again,
25
00:01:21,830 --> 00:01:24,610
hosting this on localhost 3000,
26
00:01:24,610 --> 00:01:29,380
but this is now the production ready application.
27
00:01:29,380 --> 00:01:33,200
So now if a reload this page here, it still works as before,
28
00:01:33,200 --> 00:01:36,570
but that's actually already the production ready app,
29
00:01:36,570 --> 00:01:41,570
and as you see, it's super, super fast, really good to use.
30
00:01:41,670 --> 00:01:44,070
So, that's now production ready
31
00:01:44,070 --> 00:01:45,980
and that is what we would deploy
32
00:01:45,980 --> 00:01:49,110
and do on some other computer, as well,
33
00:01:49,110 --> 00:01:52,440
and therefore, you can use any hosting provider
34
00:01:52,440 --> 00:01:54,470
that supports node JS.
35
00:01:54,470 --> 00:01:58,180
Just upload your project code, run npm install
36
00:01:58,180 --> 00:02:02,180
on that provider's machine, and then npm start,
37
00:02:02,180 --> 00:02:05,240
and then make sure that internally you forward port 3000
38
00:02:06,270 --> 00:02:09,169
to port 80 to the outside world.
39
00:02:09,169 --> 00:02:12,440
Now the exact steps for that will always differ
40
00:02:12,440 --> 00:02:15,610
based on which hosting provider you're using.
41
00:02:15,610 --> 00:02:19,480
Now, a very good hosting provider for Next.js
42
00:02:19,480 --> 00:02:21,560
is Vercel though.
43
00:02:21,560 --> 00:02:24,770
Vercel is a service of the same company
44
00:02:24,770 --> 00:02:27,320
that developed Next.js,
45
00:02:27,320 --> 00:02:31,150
and that's why Vercel is highly optimized
46
00:02:31,150 --> 00:02:35,240
for Next.js, and vice versa, I guess.
47
00:02:35,240 --> 00:02:37,390
So, you don't have to use Vercel.
48
00:02:37,390 --> 00:02:41,770
You can host Next.js on any node server, as I explained,
49
00:02:41,770 --> 00:02:45,460
but Vercel makes hosting Next.js applications
50
00:02:45,460 --> 00:02:48,280
very, very easy, especially when it comes
51
00:02:48,280 --> 00:02:51,190
to topics like scaling and so on.
52
00:02:51,190 --> 00:02:55,930
Though I will say, that there also are options like Netlify,
53
00:02:55,930 --> 00:02:59,060
which also have great Next.js support built-in,
54
00:02:59,060 --> 00:03:01,530
and which also make hosting
55
00:03:01,530 --> 00:03:05,520
and scaling Next.js applications simple.
56
00:03:05,520 --> 00:03:08,110
So definitely check out the docs of that.
57
00:03:08,110 --> 00:03:11,390
I will use Vercel as an example here though,
58
00:03:11,390 --> 00:03:14,150
also because we can get started for free
59
00:03:14,150 --> 00:03:17,180
and we don't even need a credit card.
60
00:03:17,180 --> 00:03:19,100
Now, definitely check out their pricing
61
00:03:19,100 --> 00:03:23,000
if you plan on using it for a real site.
62
00:03:23,000 --> 00:03:25,270
You can get started for free,
63
00:03:25,270 --> 00:03:28,370
but at some point it will cost you money,
64
00:03:28,370 --> 00:03:30,740
if you use certain features and so on,
65
00:03:30,740 --> 00:03:35,100
but here for our purposes, we can use the free option,
66
00:03:35,100 --> 00:03:38,150
and all we gotta do for that is sign up with them
67
00:03:38,150 --> 00:03:40,770
and create a new account, and for this here,
68
00:03:40,770 --> 00:03:44,720
we now need to sign up with GitHub, GitLab, or Bitbucket,
69
00:03:44,720 --> 00:03:47,240
and that makes sense because you will need one
70
00:03:47,240 --> 00:03:50,690
of these free options for deployment anyways.
71
00:03:50,690 --> 00:03:53,080
So therefore, before we continue here,
72
00:03:53,080 --> 00:03:54,820
let's first of all understand
73
00:03:54,820 --> 00:03:57,090
why we need one of those options.
74
00:03:57,090 --> 00:04:01,340
When deploying your Next application to Vercel,
75
00:04:01,340 --> 00:04:02,630
you deploy it such,
76
00:04:02,630 --> 00:04:07,140
that you push your code to a remote repository,
77
00:04:07,140 --> 00:04:09,410
on GitHub, GitLab, or Bitbucket,
78
00:04:09,410 --> 00:04:13,496
which are simply remote Git repository providers.
79
00:04:13,496 --> 00:04:17,110
GitHub, of course, is the most well-known one I would argue,
80
00:04:17,110 --> 00:04:21,680
and then once your code is on such a remote depository,
81
00:04:21,680 --> 00:04:24,770
you can easily connect it to your Vercel account
82
00:04:24,770 --> 00:04:27,560
and tell Vercel that whenever the code in
83
00:04:27,560 --> 00:04:30,790
that repository changes, you want to redeploy,
84
00:04:30,790 --> 00:04:34,420
and that makes redeploying super simple then
85
00:04:34,420 --> 00:04:36,880
because all you have to do is,
86
00:04:36,880 --> 00:04:41,117
you have to push your latest code to GitHub,
87
00:04:41,117 --> 00:04:43,730
and therefore, that is what we will do here.
88
00:04:43,730 --> 00:04:46,150
Now you need to have Git installed for this,
89
00:04:46,150 --> 00:04:49,330
which is a version control system,
90
00:04:49,330 --> 00:04:53,343
and you can get it for free from git-scm.com.
91
00:04:54,220 --> 00:04:55,740
You don't need to know anything
92
00:04:55,740 --> 00:04:57,690
about Git to follow along here.
93
00:04:57,690 --> 00:05:00,070
For the moment, it's enough to install it.
94
00:05:00,070 --> 00:05:02,350
If you want to learn more about Git though,
95
00:05:02,350 --> 00:05:05,680
we have a course on that, the Git and GitHub course,
96
00:05:05,680 --> 00:05:09,330
and we also got a free Git for Beginners Tutorial,
97
00:05:09,330 --> 00:05:10,720
which you can explore.
98
00:05:10,720 --> 00:05:12,350
So that might be worth a closer look
99
00:05:12,350 --> 00:05:14,410
if you want to learn more about Git,
100
00:05:14,410 --> 00:05:17,853
but here, just installing it and following along is enough.
101
00:05:18,880 --> 00:05:21,580
So once you installed Git on your system
102
00:05:21,580 --> 00:05:24,120
from that page by simply downloading it
103
00:05:24,120 --> 00:05:26,570
and walking through the installer,
104
00:05:26,570 --> 00:05:29,110
you should be able to use the Git command here
105
00:05:29,110 --> 00:05:30,203
in your terminal,
106
00:05:31,050 --> 00:05:34,460
and then as a first step, you want to run git init.
107
00:05:34,460 --> 00:05:36,110
I'm not going to run it here
108
00:05:36,110 --> 00:05:39,870
because I am already using Git in this project,
109
00:05:39,870 --> 00:05:41,840
but what git init will do,
110
00:05:41,840 --> 00:05:45,020
is it will basically just put this project
111
00:05:45,020 --> 00:05:46,653
under Gits control.
112
00:05:47,540 --> 00:05:51,810
Now, once you ran git init, you want to run git add dot,
113
00:05:51,810 --> 00:05:55,100
and git commit, some message,
114
00:05:55,100 --> 00:05:57,060
maybe a more meaningful message,
115
00:05:57,060 --> 00:06:01,100
describing what you changed since your last git commit,
116
00:06:01,100 --> 00:06:03,773
to create a code snapshot with Git.
117
00:06:05,170 --> 00:06:10,170
So here I'll say, prepared for deployment, like this.
118
00:06:10,870 --> 00:06:12,640
Now your output might differ here
119
00:06:12,640 --> 00:06:16,180
because I already did commit before,
120
00:06:16,180 --> 00:06:18,100
but if you're committing for the first time,
121
00:06:18,100 --> 00:06:21,170
you'll see some confirmation that it worked.
122
00:06:21,170 --> 00:06:24,300
Now, this simply saved all your code files
123
00:06:24,300 --> 00:06:28,500
in a Git snapshot, and you can have multiple snapshots,
124
00:06:28,500 --> 00:06:30,160
you can go back to an older one
125
00:06:30,160 --> 00:06:33,090
if you mess things up, and so on.
126
00:06:33,090 --> 00:06:35,240
By default, that will all happen
127
00:06:35,240 --> 00:06:37,770
in a branch named main.
128
00:06:37,770 --> 00:06:39,340
Here, I'm in a different branch
129
00:06:39,340 --> 00:06:40,540
because I have different projects
130
00:06:40,540 --> 00:06:43,140
for the different course sections,
131
00:06:43,140 --> 00:06:46,030
but I did now switch to the main branch as well,
132
00:06:46,030 --> 00:06:49,070
and therefore, I am in that branch at the moment.
133
00:06:49,070 --> 00:06:51,510
So now you are in the main branch.
134
00:06:51,510 --> 00:06:53,640
You can confirm this by running git branch,
135
00:06:53,640 --> 00:06:56,020
and you should see main selected.
136
00:06:56,020 --> 00:06:57,810
You are in the main branch
137
00:06:57,810 --> 00:07:01,600
and you did add such as code snapshot.
138
00:07:01,600 --> 00:07:04,790
That means your code is now saved with Git.
139
00:07:04,790 --> 00:07:07,740
As a next step, you need to create a GitHub account.
140
00:07:07,740 --> 00:07:10,610
You can do that for free by simply Googling for GitHub,
141
00:07:10,610 --> 00:07:13,990
going to github.com and sign up for GitHub.
142
00:07:13,990 --> 00:07:16,180
Again, you can do that for free.
143
00:07:16,180 --> 00:07:18,663
So let me quickly sign in with my account here,
144
00:07:19,620 --> 00:07:23,900
and once you did sign in, you can create a new repository.
145
00:07:23,900 --> 00:07:26,280
Now, here you can give this repository
146
00:07:26,280 --> 00:07:27,810
any name of your choice,
147
00:07:27,810 --> 00:07:32,440
and I'll go with nextjs-course, but the name is up to you.
148
00:07:32,440 --> 00:07:34,650
You can give it an optional description,
149
00:07:34,650 --> 00:07:38,470
and you can choose whether it should be public or private,
150
00:07:38,470 --> 00:07:42,510
both is possible, and here I'll go with private,
151
00:07:42,510 --> 00:07:45,250
and then click create repository.
152
00:07:45,250 --> 00:07:48,293
Now, no one, except for me will be able to see that.
153
00:07:49,600 --> 00:07:53,500
Now, we can grab that link here, which we see here,
154
00:07:53,500 --> 00:07:55,600
and go back to our project
155
00:07:55,600 --> 00:07:59,897
and now run git remote add origin,
156
00:08:00,890 --> 00:08:02,343
and then paste in that URL.
157
00:08:03,380 --> 00:08:07,770
This sets up a connection between your local Git repository,
158
00:08:07,770 --> 00:08:09,890
so between your local project,
159
00:08:09,890 --> 00:08:11,913
and that remote repository.
160
00:08:13,320 --> 00:08:18,320
Once you did that, you can run git push origin main,
161
00:08:19,430 --> 00:08:23,840
to push the main branch to that repository,
162
00:08:23,840 --> 00:08:25,540
and that's what we'll do now.
163
00:08:25,540 --> 00:08:27,940
Now, if you are getting a repository not found
164
00:08:27,940 --> 00:08:31,150
error message here, which you very well might,
165
00:08:31,150 --> 00:08:34,240
you need to include your log-in credentials
166
00:08:34,240 --> 00:08:36,440
into that remote URL.
167
00:08:36,440 --> 00:08:41,070
For this, we can remove that remote repository
168
00:08:41,070 --> 00:08:44,100
with git remote rm origin,
169
00:08:44,100 --> 00:08:46,770
and once you did that, run the add command again,
170
00:08:46,770 --> 00:08:48,723
but with a twist.
171
00:08:49,710 --> 00:08:53,220
Now you want to go to your GitHub account
172
00:08:54,280 --> 00:08:59,280
and there to settings, and there to developer settings,
173
00:09:01,400 --> 00:09:04,490
and here to personal access tokens.
174
00:09:04,490 --> 00:09:06,860
Click on generate new token there,
175
00:09:06,860 --> 00:09:11,610
and to add any note you want, like local development,
176
00:09:11,610 --> 00:09:14,970
and then make sure that under scopes here,
177
00:09:14,970 --> 00:09:19,970
you select repo, also adminrepo_hook and delete_repo,
178
00:09:23,620 --> 00:09:25,653
and then generate this token.
179
00:09:26,850 --> 00:09:29,670
Now that token will never be shown to you again
180
00:09:29,670 --> 00:09:32,110
but you can always generate a new one
181
00:09:32,110 --> 00:09:34,400
and you should therefore, now copy it,
182
00:09:34,400 --> 00:09:39,400
and now when you add your remote repository again,
183
00:09:39,410 --> 00:09:42,890
add a @ symbol in front of github.com,
184
00:09:42,890 --> 00:09:46,980
and then add your username here, in front of that.
185
00:09:46,980 --> 00:09:50,223
So your GitHub username, and I will do that real quick,
186
00:09:51,400 --> 00:09:56,283
and then try pushing again by running, git push origin main.
187
00:09:57,950 --> 00:10:00,950
Now, you should be prompted for your password
188
00:10:00,950 --> 00:10:04,220
and there you can use your GitHub password,
189
00:10:04,220 --> 00:10:06,390
though that method is deprecated
190
00:10:06,390 --> 00:10:08,950
and will stop to work in the future,
191
00:10:08,950 --> 00:10:12,363
and therefore instead, you should use your token,
192
00:10:14,020 --> 00:10:15,350
and once you did that,
193
00:10:15,350 --> 00:10:18,380
the code should be pushed successfully to GitHub,
194
00:10:18,380 --> 00:10:22,860
which means it's now uploaded to the remote repository,
195
00:10:22,860 --> 00:10:25,620
and if you revisit your repository,
196
00:10:25,620 --> 00:10:28,220
if you reload that repository page,
197
00:10:28,220 --> 00:10:29,923
you should see your code here,
198
00:10:31,120 --> 00:10:34,560
and now with that, we're ready to connect it to Vercel
199
00:10:34,560 --> 00:10:36,533
and deploy our application.
200
00:10:37,440 --> 00:10:39,340
For this, back here on Vercel,
201
00:10:39,340 --> 00:10:41,530
we now want to continue with GitHub here
202
00:10:41,530 --> 00:10:46,530
and sign up with GitHub, and give Vercel these permissions,
203
00:10:46,640 --> 00:10:50,570
and now here, we need to import a Git repository.
204
00:10:50,570 --> 00:10:51,917
So we need to connect Vercel
205
00:10:51,917 --> 00:10:54,920
to the repository that holds our code,
206
00:10:54,920 --> 00:10:57,480
and for this I'll click on that dropdown here,
207
00:10:57,480 --> 00:11:00,840
click on add GitHub Org or Account,
208
00:11:00,840 --> 00:11:03,310
and then I'm prompted to give Vercel access
209
00:11:03,310 --> 00:11:06,340
to the repository of my account here,
210
00:11:06,340 --> 00:11:09,250
and we can give it access to all repositories,
211
00:11:09,250 --> 00:11:13,130
or only the repositories we know we want to grant access.
212
00:11:13,130 --> 00:11:18,130
Like in this case, the nextjs-course repository,
213
00:11:18,710 --> 00:11:21,630
and I'll do that and click install,
214
00:11:21,630 --> 00:11:26,180
and now here, I can import that repository into Vercel.
215
00:11:26,180 --> 00:11:28,180
So that's what I'll do here,
216
00:11:28,180 --> 00:11:30,580
and I'll select my personal account here,
217
00:11:30,580 --> 00:11:33,650
so that I can use that free deployment option,
218
00:11:33,650 --> 00:11:35,900
and now we end up on this screen.
219
00:11:35,900 --> 00:11:39,770
Now, it detects that we have a Next.js application here,
220
00:11:39,770 --> 00:11:41,460
but we could also use Vercel
221
00:11:41,460 --> 00:11:43,810
for deploying other kinds of apps.
222
00:11:43,810 --> 00:11:46,000
It's very versatile, as you can tell,
223
00:11:46,000 --> 00:11:48,683
but of course we want to go with Next.js here.
224
00:11:49,560 --> 00:11:51,730
We can edit the root directory
225
00:11:51,730 --> 00:11:54,910
in case we would have our code in some nested directory,
226
00:11:54,910 --> 00:11:57,050
but we don't have that here.
227
00:11:57,050 --> 00:11:58,870
We can tweak some settings.
228
00:11:58,870 --> 00:12:01,850
For example, we can tell it that we want to build
229
00:12:01,850 --> 00:12:05,320
with npm run build, and we could change this,
230
00:12:05,320 --> 00:12:09,000
and I'll also stick to the default output directory,
231
00:12:09,000 --> 00:12:12,260
and we can override environment variables,
232
00:12:12,260 --> 00:12:13,900
and that is interesting,
233
00:12:13,900 --> 00:12:15,110
because that allows us
234
00:12:15,110 --> 00:12:18,510
to define production environment variables
235
00:12:18,510 --> 00:12:21,810
without using that config file for that.
236
00:12:21,810 --> 00:12:25,290
Now, here with our setup, we are already
237
00:12:25,290 --> 00:12:28,610
using different environment variables in production,
238
00:12:28,610 --> 00:12:31,510
so we don't need to add them here again,
239
00:12:31,510 --> 00:12:35,770
but, instead of having separate environment variables here
240
00:12:35,770 --> 00:12:38,920
for production, we could also inject
241
00:12:38,920 --> 00:12:43,610
our production values here in this Vercel console,
242
00:12:43,610 --> 00:12:45,880
but again, I will go with the setup I have
243
00:12:45,880 --> 00:12:49,060
in the config file, hence, I'll leave that empty
244
00:12:49,060 --> 00:12:50,890
and click on deploy,
245
00:12:50,890 --> 00:12:55,630
and now Vercel will build our application and then start it,
246
00:12:55,630 --> 00:12:58,890
and it will automatically build our pages
247
00:12:58,890 --> 00:13:00,490
and pre-rendered pages,
248
00:13:00,490 --> 00:13:03,100
it will host those on a CDN then,
249
00:13:03,100 --> 00:13:07,970
which is optimized for speed and has great caching settings,
250
00:13:07,970 --> 00:13:11,770
and it will then also, take our API routes
251
00:13:11,770 --> 00:13:14,920
and put those into serverless functions,
252
00:13:14,920 --> 00:13:18,800
which are executed on demand and scale infinitely
253
00:13:18,800 --> 00:13:21,100
in a cost effective way.
254
00:13:21,100 --> 00:13:23,270
So it's a great deployment option
255
00:13:23,270 --> 00:13:26,353
and we don't need to do anything else to make it work.
256
00:13:27,370 --> 00:13:30,570
So let's now wait for this deployment process
257
00:13:30,570 --> 00:13:32,420
to finish here.
258
00:13:32,420 --> 00:13:35,690
We see the same output as we did locally.
259
00:13:35,690 --> 00:13:37,850
Now it's basically wiring everything up
260
00:13:37,850 --> 00:13:41,163
with the Vercel's servers and machines,
261
00:13:42,110 --> 00:13:45,630
and looks like it's about to be done.
262
00:13:45,630 --> 00:13:47,950
Here we go, it's deployed,
263
00:13:47,950 --> 00:13:49,990
and now we can click Visit,
264
00:13:49,990 --> 00:13:54,840
and we see our application running in the web.
265
00:13:54,840 --> 00:13:57,700
As you see there, everything works
266
00:13:57,700 --> 00:14:00,650
just as it worked locally.
267
00:14:00,650 --> 00:14:04,460
So that is working and now it is hosted in the web.
268
00:14:04,460 --> 00:14:09,140
It's not hosted locally and we hosted it with Vercel.
269
00:14:09,140 --> 00:14:11,270
Now you can go to the dashboard here
270
00:14:11,270 --> 00:14:14,070
and then configure more things here.
271
00:14:14,070 --> 00:14:15,910
You can assign a custom domain.
272
00:14:15,910 --> 00:14:17,270
You can monitor it.
273
00:14:17,270 --> 00:14:21,720
You can dive into the logs, explore certain analytics,
274
00:14:21,720 --> 00:14:24,080
dive into the settings and configure it,
275
00:14:24,080 --> 00:14:26,120
and do things like that.
276
00:14:26,120 --> 00:14:28,990
Definitely, play around with those settings
277
00:14:28,990 --> 00:14:32,120
and those options, if you are using Vercel
278
00:14:32,120 --> 00:14:34,083
for your production ready app.
279
00:14:35,080 --> 00:14:36,800
Now, the great thing is,
280
00:14:36,800 --> 00:14:39,200
that if we now want to change something,
281
00:14:39,200 --> 00:14:41,400
let's say in our contact form,
282
00:14:41,400 --> 00:14:45,960
I want to change the text in the success notification.
283
00:14:45,960 --> 00:14:49,020
I want to add a couple of exclamation marks.
284
00:14:49,020 --> 00:14:51,190
Then we just make that change,
285
00:14:51,190 --> 00:14:53,150
We then create a new Git snapshot
286
00:14:53,150 --> 00:14:55,760
with git add and git commit,
287
00:14:55,760 --> 00:14:58,130
changed notification message,
288
00:14:58,130 --> 00:15:00,813
sounds like a good note here,
289
00:15:01,660 --> 00:15:05,890
and then we push again by pushing main to origin,
290
00:15:05,890 --> 00:15:08,290
and when we do that,
291
00:15:08,290 --> 00:15:10,830
when we make that push,
292
00:15:10,830 --> 00:15:15,270
Vercel will automatically recognize that.
293
00:15:15,270 --> 00:15:17,040
It automatically recognizes this
294
00:15:17,040 --> 00:15:20,390
and starts building again, as you can see here.
295
00:15:20,390 --> 00:15:23,200
So it recognizes, pushes to main,
296
00:15:23,200 --> 00:15:26,060
because that is the connected main branch here,
297
00:15:26,060 --> 00:15:28,800
and whenever the code in that branch changes,
298
00:15:28,800 --> 00:15:32,320
it will rebuild and redeploy our application,
299
00:15:32,320 --> 00:15:34,030
which is of course pretty amazing
300
00:15:34,030 --> 00:15:36,870
and makes redeploying a breeze.
301
00:15:36,870 --> 00:15:41,250
So, let's wait for that rebuilding here to finish.
302
00:15:41,250 --> 00:15:43,150
Here we go, looks like it's done,
303
00:15:43,150 --> 00:15:45,380
and then visit the updated page,
304
00:15:45,380 --> 00:15:49,390
which is of course served on the same domain,
305
00:15:49,390 --> 00:15:51,760
and now here, if we give this a try
306
00:15:51,760 --> 00:15:55,360
to see if everything works, does that work?
307
00:15:55,360 --> 00:15:59,090
If I send a message, I get an error,
308
00:15:59,090 --> 00:16:02,090
could not connect to database.
309
00:16:02,090 --> 00:16:04,920
And why are we getting this error?
310
00:16:04,920 --> 00:16:06,890
Well, you could think that it's a problem
311
00:16:06,890 --> 00:16:10,330
with our environment variables, but that's not the case.
312
00:16:10,330 --> 00:16:13,640
We did set those in our config folder
313
00:16:13,640 --> 00:16:16,000
in our config file,
314
00:16:16,000 --> 00:16:19,740
but keep in mind that we're using MongoDB Atlas,
315
00:16:19,740 --> 00:16:22,810
and here we need to control who's able to connect.
316
00:16:22,810 --> 00:16:25,230
We do this under network access,
317
00:16:25,230 --> 00:16:29,970
and we added our local IP address, but now it was deployed,
318
00:16:29,970 --> 00:16:33,590
and now to ensure that this deployed application,
319
00:16:33,590 --> 00:16:35,840
which is running on some remote server,
320
00:16:35,840 --> 00:16:38,646
that this can connect to MongoDB Atlas,
321
00:16:38,646 --> 00:16:40,710
we need to add another IP address,
322
00:16:40,710 --> 00:16:43,810
and if we know the IP off the server, we could add that,
323
00:16:43,810 --> 00:16:45,160
but since we don't know it,
324
00:16:45,160 --> 00:16:47,490
we want to allow access from anywhere.
325
00:16:47,490 --> 00:16:50,550
We still have the password username protection in place,
326
00:16:50,550 --> 00:16:53,400
but we need to enable all IPs to connect
327
00:16:53,400 --> 00:16:58,150
to ensure that our deployed application also can connect.
328
00:16:58,150 --> 00:17:00,460
Otherwise, all these environment variables
329
00:17:00,460 --> 00:17:03,580
don't do anything if we block the connection
330
00:17:03,580 --> 00:17:05,502
from MongoDB's side.
331
00:17:06,369 --> 00:17:08,329
So let's wait for this update
332
00:17:08,329 --> 00:17:12,829
to be in effect here on MongoDB Atlas,
333
00:17:12,829 --> 00:17:17,329
so that all hosts can connect to this database,
334
00:17:17,329 --> 00:17:20,640
and once this is done, let's try sending this message again,
335
00:17:20,640 --> 00:17:21,920
and now we have a success
336
00:17:21,920 --> 00:17:23,839
and we see all the exclamation marks.
337
00:17:23,839 --> 00:17:25,839
So now that works,
338
00:17:25,839 --> 00:17:29,810
and that's how we can deploy our Next application
339
00:17:29,810 --> 00:17:34,250
with npm run build with that server-side code with Vercel.
340
00:17:34,250 --> 00:17:36,360
It's not the only option, but as you saw,
341
00:17:36,360 --> 00:17:38,513
it's very, very easy to use it.
27216
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.