Dab tsi yog Middleware ua haujlwm hauv Express?
Dab tsi yog Middleware ua haujlwm hauv Express?

Video: Dab tsi yog Middleware ua haujlwm hauv Express?

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

Middleware ua haujlwm yog muaj nuj nqi uas muaj kev nkag mus rau cov khoom thov (req), cov khoom teb (res), thiab lwm yam muaj nuj nqi nyob rau hauv daim ntawv thov kev thov-teb lub voj voog. Tom ntej no muaj nuj nqi yog a muaj nuj nqi hauv Qhia router uas, thaum invoked, executes lub khoom nruab nrab ua tiav qhov tam sim no khoom nruab nrab.

Xav txog qhov no, dab tsi yog Middleware hauv Express?

Middleware txhais tau tias txhua yam koj muab tso rau hauv nruab nrab ntawm ib txheej ntawm software thiab lwm yam. Qhia nruab nrab yog cov haujlwm uas ua haujlwm thaum lub sijhawm ua haujlwm ntawm kev thov mus rau Qhia server. Txhua khoom nruab nrab muaj kev nkag mus rau HTTP thov thiab teb rau txhua txoj kev (lossis txoj hauv kev) nws txuas nrog.

Qhov thib ob, dab tsi yog siv hauv Express? siv yog ib txoj hauv kev los teeb tsa cov khoom nruab nrab siv los ntawm txoj kev ntawm lub Qhia HTTP server object. Txoj kev yog txhais raws li ib feem ntawm Txuas uas Qhia yog nyob ntawm. Hloov tshiab Pib nrog version 4.

Tom qab ntawd, 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.

Koj nkag siab dab tsi los ntawm middleware Koj tuaj yeem siv cov khoom nruab nrab hauv node JS li cas?

Middleware yog ib pawg ntawm chained functions hu ua Express js routing txheej ua ntej tus neeg siv-txhais handler yog invoked. Middleware functions muaj kev nkag mus rau tag nrho rau thov thiab teb cov khoom thiab ua tau hloov kho ib qho ntawm lawv.

Pom zoo: