Middleware
Handling middleware within Octoris
Last updated
Was this helpful?
Handling middleware within Octoris
Last updated
Was this helpful?
Octoris supports middleware at 3 stages:
Global Stage, this is directly after the route is hit, the only missing piece from context here is params
Route Stage, this is middleware attached to a route directly, full context is available here
Method Stage, This is middleware attached directly to methods on a route, full context is available here
- A static file server middleware
- A body parser middleware
- A multipart form/file middleware
Middleware used at the very beginning of a route being triggered, this is provided to the function as the 3rd parameter
In the above example, we have it setup so anytime we hit a route the middleware functions 1 and 2 will be called first. The functions are read from the array from left to right.
This stage is the last to trigger and happens AFTER the route stage. This middleware is attached specifically to a method so it only triggers when that method is used.
Middleware in the route stage will fire immediately after the global stage middleware, these are functions attached directly to a route that will trigger regardless of what method was used. These are provided to the function directly