Dab tsi yog Middleware hauv NodeJS?
Dab tsi yog Middleware hauv NodeJS?

Video: Dab tsi yog Middleware hauv NodeJS?

Video: Dab tsi yog Middleware hauv NodeJS?
Video: Hmong new song 2016 - Yog dab tsi - Xub Hluav Taws (Official MV) 2024, Kaum ib hlis
Anonim

Middleware cov haujlwm yog cov haujlwm uas muaj kev nkag mus rau cov khoom thov (req), cov khoom teb (res), thiab lwm yam khoom nruab nrab muaj nuj nqi nyob rau hauv daim ntawv thov lub voj voog thov- teb. Tom ntej no khoom nruab nrab muaj nuj nqi yog feem ntau denoted los ntawm ib tug kuj sib txawv lub npe tom ntej.

Ntxiv mus, dab tsi yog kev siv cov khoom nruab nrab hauv node JS?

Middleware yog ib tug subset ntawm chained functions hu ua los ntawm lub Qhia js routing txheej ua ntej tus neeg siv-txhais handler yog invoked. Middleware functions muaj kev nkag mus rau tag nrho cov lus thov thiab cov khoom teb thiab tuaj yeem hloov kho ib qho ntawm lawv.

Kuj Paub, Bodyparser yog dab tsi hauv NodeJs? cev-parser rho tag nrho lub cev ib feem ntawm qhov kev thov nkag kwj thiab nthuav tawm nws ntawm req. cev. Cov khoom nruab nrab yog ib feem ntawm Express. js ua ntej tab sis tam sim no koj yuav tsum nruab nws nyias. Qhov no cev-parser module parses JSON, tsis, hlua thiab URL encoded cov ntaub ntawv xa tuaj siv HTTP POST thov.

Hauv qhov no, kuv yuav siv Express Middleware li cas?

Ib Qhia daim ntawv thov tuaj yeem siv hom hauv qab no ntawm khoom nruab nrab : Application-level khoom nruab nrab . Router theem khoom nruab nrab . Kev ua yuam kev khoom nruab nrab.

Siv cov khoom nruab nrab

  1. Ua txhua qhov chaws.
  2. Hloov cov lus thov thiab cov khoom teb.
  3. Xaus lub voj voog kev thov teb.
  4. Hu rau cov haujlwm nruab nrab tom ntej hauv pawg.

Route Middleware yog dab tsi?

Thaum koj xav tau a khoom nruab nrab rau qhov tshwj xeeb txoj kev , koj yuav tsum ntxiv cov khoom nruab nrab nrog tus yuam sij rau koj lub app/Http/Kernel. php cov ntaub ntawv, thiab cov khoom nruab nrab no hu ua txoj kev nruab nrab.

Pom zoo: