๐ก Middleware allows you to run code before a request is completed. Then, based on the incoming request, you can modify the response by rewriting, redirecting, modifying the request or response headers, or responding directly.
(์ถ์ฒ: next ๊ณต์ ๋ฌธ์)
์ฆ, ๋ฏธ๋ค์จ์ด๋ ์์ฒญ์ด ์๋ฃ๋๊ธฐ ์ ์ ์คํ๋๋ ์ฝ๋.
๋ค์ ์์ฒญ์ ๋ฐ๋ผ ์์ฒญ or ์๋ต ํค๋๋ ์์ ์ด๋ ์๋ต ์์ ์ด ๊ฐ๋ฅํฉ๋๋ค.
NextReseponse API๋ฅผ ํตํด ํ ์ ์๋ ์์ ๋ค
- redirect/rewrite ์์
- redirect: ๋ค๋ฅธ url๋ก ์ด๋
- rewrite: ์ฃผ์ด์ง url์ ๋ํด response ๋ณ๊ฒฝ
- cookie get/set ํ ๊ฐ๊ณตํ๋ ์์
- header response ์ค์
Next์ middleware๋ฅผ ํตํด ํ ์ ์๋ ์์ ๋ค
- ์ธ์ฆ ๊ด๋ จ ์์
- ๋ฏธ๋ค์จ์ด๋ฅผ ํตํด ์ธ์ฆ ์ํ ํ์ธ
- ๋ฏธ ๋ก๊ทธ์ธ ์ํ ์ ๋ก๊ทธ์ธ ํ์ด์ง๋ก ๋ฆฌ๋ค์ด๋ ์
- ๋ผ์ฐํ
๋ณดํธ
- ํน์ ์ฌ์ฉ์๋ค์๊ฒ๋ง ํ์ฉ๋๋ ๊ฒฝ๋ก์ ๋ํ ์ก์ธ์ค ์ ํ
- API ์์ฒญ ์ ์ฒ๋ฆฌ
- ๋ฐ์์จ ๋ฐ์ดํฐ ๊ฐ๊ณต
- ํค๋ ์ถ๊ฐ ๋๋ ์์
- ๋ก๊น
๊ณผ ๋ถ์
- ์์ฒญ / ์๋ต์ ๋ก๊น ๋ฐ ๋ถ์
- ์ด๋ฅผ ํตํ ์ฌ์ฉ์ ํ๋ ์ถ์ ๋ฐ ์ฑ๋ฅ ๋ชจ๋ํฐ๋ง ๊ธฐ๋ฅ ๊ตฌํ ๊ฐ๋ฅ
- ์บ์ ๋ฐ ์ฑ๋ฅ ์ต์ ํ
- DB ์ฟผ๋ฆฌ ๊ฒฐ๊ณผ ์บ์ฑ