Middleware ਇੱਕ hooks ਦਾ framework ਹੈ ਜੋ ਹਰ request ਅਤੇ response ਨੂੰ globally ਪ੍ਰਸੰਸਕਰਤ ਕਰਦਾ ਹੈ, ਜੋ web server ਅਤੇ ਤੁਹਾਡੇ views ਦੇ ਵਿਚਕਾਰ ਬੈਠਾ ਹੁੰਦਾ ਹੈ। ਹਰ middleware incoming ਸਮੇਂ requests ਨੂੰ inspect/modify ਕਰ ਸਕਦਾ ਹੈ ਅਤੇ outgoing ਸਮੇਂ responses ਨੂੰ — authentication, security headers, sessions, ਅਤੇ logging ਜਿਵੇਂ cross-cutting concerns ਲਈ ideal ਹੈ।
Middleware ਰਾਹੀਂ request/response flow
Request → MW1 → MW2 → MW3 → VIEW
Response ← MW1 ← MW2 ← MW3 ← VIEW
Middleware wraps the view like layers of an onion:
- on the way IN (request): top-to-bottom
- on the way OUT (response): bottom-to-top (reverse order)
