Sunday, November 17, 2019

What is Middleware in Sails JS



In an MVC framework, the term “middleware” typically refers more specifically to code that runs before or after your route-handling code (i.e. your controller actions), making it possible to apply the same piece of code to multiple routes or actions.

Below are the various middleware actions available in sails

HTTP middleware—to apply code before every HTTP request (see below for more details)
Policies—to apply code before one or more controller actions
Hooks with the routes feature implemented—to apply code before one or more route handlers
Custom responses—to apply code after one or more controller actions

HTTP middleware

Sails is fully compatible with Express / Connect middleware, which are functions that accept req, res and next as arguments. Every app utilizes a configurable middleware stack for handling HTTP requests. Each time the app receives an HTTP request, its configured HTTP middleware stack runs in order.



References:
https://sailsjs.com/documentation/concepts/middleware

No comments:

Post a Comment