[Nest.js] Middle Ware(๋ฏธ๋“ค์›จ์–ด)

2022. 4. 11. 22:02ใ†Back-End ์ž‘์—…์‹ค/Node.js

728x90
๋ฐ˜์‘ํ˜•

 

๐Ÿš€ Nest.js์˜ Middle Ware

    ๐Ÿ”ฝ  ๊ฐœ์š”

`Pipes`, `Filters`, `Guards`, `Interceptors` ๋“ฑ์ด `Nest.js`์—์„œ๋Š” ๋ฏธ๋“ค์›จ์–ด๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๊ฒƒ์ด์—์š”.

 

 

 

 

    ๐Ÿ”ฝ  ๋Œ€ํ‘œ Middle Ware

์ด   ๋ฆ„ ๋‚ด    ์šฉ
Pipes Pipe๋Š” Client ์š”์ฒญ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ ๋ฐ Payload ๋ณ€ํ™˜์„ ์œ„ํ•ด ์‚ฌ์šฉ.
Data๋ฅผ ์˜ˆ์ƒํ•œ ๋Œ€๋กœ ์ง๋ ฌํ™”.

์ž์„ธํ•œ ์„ค๋ช…
Filters ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ ๋ฏธ๋“ค์›จ์–ด.
ํŠน์ • ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ๊ธฐ๋ฅผ ์‚ฌ์šฉํ•  ๊ฒฝ๋กœ์™€ ๊ฐ ๊ฒฝ๋กœ ์ฃผ๋ณ€์˜ ๋ณต์žก์„ฑ์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ฐฉ๋ฒ• ์ œ๊ณต.
Guards ์ธ์ฆ ๋ฏธ๋“ค์›จ์–ด.
์ง€์ •๋œ ๊ฒฝ๋กœ๋กœ ํ†ต๊ณผํ•  ์ˆ˜ ์žˆ๋Š” Client์™€ ๊ทธ๋ ‡์ง€ ์•Š๋Š” Client์— ๋Œ€ํ•ด Server์—๊ฒŒ ๋‚ด์šฉ ์ œ๊ณต. 
Interceptors ์‘๋‹ต Mapping ๋ฐ ์บ์‹œ ๊ด€๋ฆฌ์™€ ์š”์ฒญ Logging๊ณผ ๊ฐ™์€ ์ „ ํ›„ ๋ฏธ๋“ค์›จ์–ด.
๊ฐ Request ์ „ ํ›„์— ์ด๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๊ธฐ๋Šฅ์„ ๋งค์šฐ ๊ฐ•๋ ฅํ•˜๊ณ  ์œ ์šฉ
๋ฐ˜์‘ํ˜•

๊ฐ๊ฐ Middle Ware๊ฐ€ ํ˜ธ์ถœ(Called)๋˜๋Š” ์ˆœ์„œ

1. Middleware
2. Guard
3. Interceptor (before)
4. Pipe
5. Controller
6. Service
7. Repository
8. Data Base
9. Repository
10. Service
11. Controller
12. Interceptor (after)
13. Filter ( if Applicable)
14. Client

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•