Skip to content

Commit 2c8af25

Browse files
committed
Merge branch 'source' into part5-spanish
2 parents 87af8a9 + 7368d03 commit 2c8af25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+7117
-684
lines changed

src/components/InfoBanner.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,9 @@ const InfoBanner = ({ visible, onHide }) => {
4646
<div style={style}>
4747
<div style={textStyle}>
4848
<p>
49-
There are some changes in part 9. The <i>Patientor</i> example app
50-
structure has been refactored to a less complex form to make it easier
51-
to concentrate on learning TypeScript.
49+
The testing library used in part 4 was changed 13th February 2024 from Jest to Node:test.
50+
If you have started with Jest, you may continue. The relevant material is still available, see the "Legacy: testing with Jest"
5251
</p>
53-
<div style={{ marginTop: 10 }}>
54-
If you are just working with the old Patientor, no worries, the old
55-
material shall stay online for a couple of weeks.
56-
</div>
57-
58-
<div style={{ marginTop: 10 }}>
59-
<i>
60-
If you have already completed the part 9, this change has absolutely
61-
no effect on your progress.
62-
</i>
63-
</div>
6452
</div>
6553
<div style={buttonDiv}>
6654
<button style={buttonStyle} onClick={onHide}>

src/components/layout.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Footer from './Footer/Footer';
1010
import PropTypes from 'prop-types';
1111
import SkipToContent from './SkipToContent/SkipToContent';
1212

13-
const BANNER_TO_KEY = 'part_9_changes';
13+
const BANNER_TO_KEY = 'part_4_changes';
1414

1515
const Layout = props => {
1616
const { i18n } = useTranslation();
@@ -23,7 +23,8 @@ const Layout = props => {
2323
useEffect(() => {
2424
const key = localStorage.getItem(BANNER_TO_KEY)
2525
if (!key) {
26-
setVisible(true);
26+
const relevant = window.location.href.includes('osa4') || window.location.href.includes('en/part4')
27+
setVisible(relevant);
2728
}
2829
}, []);
2930

@@ -38,7 +39,7 @@ const Layout = props => {
3839

3940
<Header lang={siteLanguage} />
4041

41-
<InfoBanner onHide={() => hideNote()} visible={false} />
42+
<InfoBanner onHide={() => hideNote()} visible={visible} />
4243

4344
<main id="main-content">{children}</main>
4445

src/content/13/en/part13a.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ We can use the _heroku config_ command to get the <i>connect string</i>, which i
112112
```bash
113113
heroku config -a <app-name>
114114
=== cryptic-everglades-76708 Config Vars
115-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
115+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
116116
```
117117

118118
The database can be accessed by running _psql_ command on the Heroku server as follows (note that the command parameters depend on the connection url of the Heroku database):
@@ -317,7 +317,7 @@ If Heroku is used, the connect string can be seen by using the command _heroku c
317317

318318
```bash
319319
$ cat .env
320-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
320+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
321321
```
322322

323323
When using Fly.io, the local connection to the database should first be enabled by [tunneling](https://fly.io/docs/reference/postgres/#connecting-to-postgres-from-outside-fly)
@@ -339,7 +339,7 @@ The Fly.io connect-string is of the form
339339

340340
```bash
341341
$ cat .env
342-
DATABASE_URL=postgres://postgres:<password>@127.0.0.1:5432/postgres
342+
DATABASE_URL=postgres://postgres:thepasswordishere@127.0.0.1:5432/postgres
343343
```
344344

345345
Password was shown when the database was created, so hopefully you have not lost it!

src/content/13/es/part13a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ heroku create
8181
heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
8282
heroku config -a <app-name>
8383
=== cryptic-everglades-76708 Config Vars
84-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
84+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
8585
```
8686

8787
Particularmente cuando se utiliza una base de datos relacional, también es esencial acceder a la base de datos directamente. Hay muchas maneras de hacer esto, hay varias interfaces gráficas de usuario diferentes, como [pgAdmin](https://www.pgadmin.org/). Sin embargo, utilizaremos la herramienta de línea de comandos de Postgres [psql](https://www.postgresql.org/docs/current/app-psql.html).
@@ -236,7 +236,7 @@ La <i>cadena de conexión</i> de la base de datos, que es revelada por el comand
236236
237237
```bash
238238
$ cat .env
239-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
239+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
240240
```
241241
242242
Probemos una conexión exitosa:

src/content/13/fi/osa13a.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ heroku create
108108
heroku addons:create heroku-postgresql:hobby-dev
109109
heroku config
110110
=== cryptic-everglades-76708 Config Vars
111-
DATABASE_URL: postgres://<username>:<password>@ec2-44-199-83-229.compute-1.amazonaws.com:5432/<db-name>
111+
DATABASE_URL: postgres://<username>:thepasswordishere@ec2-44-199-83-229.compute-1.amazonaws.com:5432/<db-name>
112112
```
113113

114114
Tietokantaan saadaan psql-konsoliyhteys suorittamalla _psql_ Herokun palvelimella seuraavasti (huomaa, että komennon parametrit riippuvat Heroku-sovelluksen connect urlista):
@@ -308,7 +308,7 @@ Herokua käyttäessäsi saat connect stringin selville komennolla _heroku config
308308
309309
```bash
310310
$ cat .env
311-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
311+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
312312
```
313313
314314
Fly.io:a käyttäessä paikallinen tietokantayhteys taytyy ensin tehdä mahdolliseksi [tunneloimalla](https://fly.io/docs/reference/postgres/#connecting-to-postgres-from-outside-fly) paikallisen koneen portti 5432 Fly.io:n tietokannan porttiin komennolla
@@ -329,7 +329,7 @@ Fly.io:n connect-string on seuraavaa muotoa:
329329
330330
```bash
331331
$ cat .env
332-
DATABASE_URL=postgres://postgres:<password>@localhost:5432/postgres
332+
DATABASE_URL=postgres://postgres:thepasswordishere@localhost:5432/postgres
333333
```
334334
335335
Salasana on se, jonka on otettu talteen tietokantaa luodessa.

src/content/13/zh/part13a.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ heroku create
9797
heroku addons:create heroku-postgresql:hobby-dev -a <app-name>
9898
heroku config -a <app-name>
9999
=== cryptic-everglades-76708 Config Vars
100-
DATABASE_URL: postgres://<username>:<password>@<host-of-postgres-addon>:5432/<db-name>
100+
DATABASE_URL: postgres://<username>:thepasswordishere@<host-of-postgres-addon>:5432/<db-name>
101101
```
102102

103103
<!-- Particularly when using a relational database, it is essential to access the database directly as well. There are many ways to do this, there are several different graphical user interfaces, such as [pgAdmin](https://www.pgadmin.org/). However, we will be using Postgres [psql](https://www.postgresql.org/docs/current/app-psql.html) command-line tool.-->
@@ -262,7 +262,7 @@ The database <i>connect string</i>, which is revealed by the _heroku config_ com
262262

263263
```bash
264264
$ cat .env
265-
DATABASE_URL=postgres://<username>:<password>@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
265+
DATABASE_URL=postgres://<username>:thepasswordishere@ec2-54-83-137-206.compute-1.amazonaws.com:5432/<databasename>
266266
```
267267

268268
Let's test for a successful connection:

src/content/3/en/part3.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ lang: en
88

99
In this part our focus shifts towards the backend, that is, towards implementing functionality on the server side of the stack. We will implement a simple REST API in Node.js by using the Express library, and the application's data will be stored in a MongoDB database. At the end of this part, we will deploy our application to the internet.
1010

11-
<i>Part updated 14th August 2023</i>
12-
- <i>Create React App replaced with Vite</i>
11+
<i>Part updated 9th February 2024</i>
12+
- <i>No major changes</i>
1313

1414
</div>

src/content/3/en/part3a.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ echo "Error: no test specified" && exit 1
9393

9494
### Simple web server
9595

96-
Let's change the application into a web server by editing the _index.js_ file as follow:
96+
Let's change the application into a web server by editing the _index.js_ file as follows:
9797

9898
```js
9999
const http = require('http')
@@ -120,7 +120,7 @@ We can open our humble application in the browser by visiting the address <http:
120120

121121
The server works the same way regardless of the latter part of the URL. Also the address <http://localhost:3001/foo/bar> will display the same content.
122122

123-
**NB** if port 3001 is already in use by some other application, then starting the server will result in the following error message:
123+
**NB** If port 3001 is already in use by some other application, then starting the server will result in the following error message:
124124

125125
```bash
126126
➜ hello npm start
@@ -138,7 +138,7 @@ Error: listen EADDRINUSE :::3001
138138
at listenInCluster (net.js:1378:12)
139139
```
140140

141-
You have two options. Either shut down the application using port 3001 (the json-server in the last part of the material was using port 3001), or use a different port for this application.
141+
You have two options. Either shut down the application using port 3001 (the JSON Server in the last part of the material was using port 3001), or use a different port for this application.
142142

143143
Let's take a closer look at the first line of the code:
144144

@@ -154,7 +154,7 @@ import http from 'http'
154154

155155
These days, code that runs in the browser uses ES6 modules. Modules are defined with an [export](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/export) and taken into use with an [import](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import).
156156

157-
However, Node.js uses so-called [CommonJS](https://en.wikipedia.org/wiki/CommonJS) modules. The reason for this is that the Node ecosystem needed modules long before JavaScript supported them in the language specification. Node supports now also the use of ES6 modules, but since the support is not quite perfect yet, we'll stick to CommonJS modules.
157+
Node.js uses by default so-called [CommonJS](https://en.wikipedia.org/wiki/CommonJS) modules. The reason for this is that the Node ecosystem needed modules long before JavaScript supported them in the language specification. Currently, Node also supports the use of ES6 modules, but since the support is not quite perfect yet, we'll stick to CommonJS modules.
158158

159159
CommonJS modules function almost exactly like ES6 modules, at least as far as our needs in this course are concerned.
160160

@@ -251,7 +251,7 @@ The source code for the dependency is installed in the <i>node\_modules</i> dire
251251

252252
These are the dependencies of the express library and the dependencies of all of its dependencies, and so forth. These are called the [transitive dependencies](https://lexi-lambda.github.io/blog/2016/08/24/understanding-the-npm-dependency-model/) of our project.
253253

254-
The version 4.18.2 of express was installed in our project. What does the caret in front of the version number in <i>package.json</i> mean?
254+
Version 4.18.2 of Express was installed in our project. What does the caret in front of the version number in <i>package.json</i> mean?
255255

256256
```json
257257
"express": "^4.18.2"
@@ -273,7 +273,7 @@ Likewise, if we start working on the project on another computer, we can install
273273
npm install
274274
```
275275

276-
If the <i>major</i> number of a dependency does not change, then the newer versions should be [backwards compatible](https://en.wikipedia.org/wiki/Backward_compatibility). This means that if our application happened to use version 4.99.175 of express in the future, then all the code implemented in this part would still have to work without making changes to the code. In contrast, the future 5.0.0 version of express [may contain](https://expressjs.com/en/guide/migrating-5.html) changes that would cause our application to no longer work.
276+
If the <i>major</i> number of a dependency does not change, then the newer versions should be [backwards compatible](https://en.wikipedia.org/wiki/Backward_compatibility). This means that if our application happened to use version 4.99.175 of Express in the future, then all the code implemented in this part would still have to work without making changes to the code. In contrast, the future 5.0.0 version of Express [may contain](https://expressjs.com/en/guide/migrating-5.html) changes that would cause our application to no longer work.
277277

278278
### Web and express
279279

@@ -379,7 +379,7 @@ The contents of <i>package.json</i> have also changed:
379379
"express": "^4.18.2"
380380
},
381381
"devDependencies": {
382-
"nodemon": "^2.0.20"
382+
"nodemon": "^3.0.3"
383383
}
384384
}
385385
```
@@ -603,8 +603,8 @@ Many tools exist for making the testing of backends easier. One of these is a co
603603
Let's install the Postman desktop client [from here](https://www.postman.com/downloads/) and try it out:
604604

605605
![postman screenshot on api/notes/2](../../images/3/11x.png)
606-
NB: Postman is also available on VS Code which can be dowloaded from the Extension tab on the left -> search for Postman -> First result (Verified Publisher) -> Install
607-
You will then see an extra icon added on the activity bar below the extensions tab. Once you login, you can follow from the steps below
606+
NB: Postman is also available on VS Code which can be downloaded from the Extension tab on the left -> search for Postman -> First result (Verified Publisher) -> Install
607+
You will then see an extra icon added on the activity bar below the extensions tab. Once you log in, you can follow the steps below
608608

609609
Using Postman is quite easy in this situation. It's enough to define the URL and then select the correct request type (DELETE).
610610

@@ -672,9 +672,9 @@ The application prints the data that we sent in the request to the console:
672672

673673
**NB** <i>Keep the terminal running the application visible at all times</i> when you are working on the backend. Thanks to Nodemon any changes we make to the code will restart the application. If you pay attention to the console, you will immediately be able to pick up on errors that occur in the application:
674674

675-
![nodemon error as typing requre not defined](../../images/3/16.png)
675+
![nodemon error as typing requre not defined](../../images/3/16e.png)
676676

677-
Similarly, it is useful to check the console for making sure that the backend behaves as we expect it to in different situations, like when we send data with an HTTP POST request. Naturally, it's a good idea to add lots of <em>console.log</em> commands to the code while the application is still being developed.
677+
Similarly, it is useful to check the console to make sure that the backend behaves as we expect it to in different situations, like when we send data with an HTTP POST request. Naturally, it's a good idea to add lots of <em>console.log</em> commands to the code while the application is still being developed.
678678

679679
A potential cause for issues is an incorrectly set <i>Content-Type</i> header in requests. This can happen with Postman if the type of body is not defined correctly:
680680

0 commit comments

Comments
 (0)