Skip to content

Commit 3ed70de

Browse files
committed
Clarify middleware placing
1 parent 37d13f1 commit 3ed70de

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/content/3/en/part3c.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,7 @@ app.use(express.json())
822822

823823
Then the JSON data sent with the HTTP requests would not be available for the logger middleware or the POST route handler, since the _request.body_ would be _undefined_ at that point.
824824

825-
It's also important that the middleware for handling unsupported routes is next to the last middleware that is loaded into Express, just before the error handler.
826-
827-
For example, the following loading order would cause an issue:
825+
It's also important that the middleware for handling unsupported routes is loaded only after all the endpoints have been defined, just before the error handler. For example, the following loading order would cause an issue:
828826

829827
```js
830828
const unknownEndpoint = (request, response) => {

src/content/3/fi/osa3c.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ Koska middlewaret suoritetaan siinä järjestyksessä, missä ne on otettu käyt
790790
Oikeaoppinen järjestys on tämä:
791791

792792
```js
793-
app.use(express.static('build'))
793+
app.use(express.static('dist'))
794794
app.use(express.json())
795795
app.use(requestLogger)
796796

@@ -830,9 +830,7 @@ app.use(express.json())
830830

831831
ei HTTP-pyynnön mukana oleva data olisi loggerin eikä POST-pyynnön käsittelyn aikana käytettävissä, vaan kentässä _request.body_ olisi tyhjä olio.
832832

833-
Tärkeää on myös ottaa käyttöön olemattomien osoitteiden käsittely viimeisenä.
834-
835-
Myös seuraava järjestys aiheuttaisi ongelman:
833+
Tärkeää on myös ottaa olemattomat osoitteet käsittelevä middleware käyttöön vasta kaikkien endpointtien määrittelyn jälkeen, juuri ennen virheenkäsittelijää. Seuraava järjestys aiheuttaisi ongelman:
836834

837835
```js
838836
const unknownEndpoint = (request, response) => {

0 commit comments

Comments
 (0)