const mixinafBedSheet::Middleware
afBedSheet::Middleware
Implement to define BedSheet middleware.
HTTP requests are funnelled through a stack of middleware instances until either one of them returns true
, or they reach a terminator. The default BedSheet terminator returns a 404 error.
Middleware may perform processing before and / or after passing the request down the pipeline to other middleware instances. Use middleware to address cross cutting concerns such as authentication and authorisation. See the FantomFactory article Basic HTTP Authentication With BedSheet for examples.
Because middleware effectively wrap other middleware instances and each can terminate the pipeline prematurely, the ordering of middleware is extremely important.
Route
instances are processed in the Routes
middleware. So generally you would explicitly contribute your own middleware to be before or after this.
IOC Configuration
Instances of Middleware
should be contributed to the MiddlewarePipeline
service.
For example, in your AppModule
class:
@Contribute { serviceType=MiddlewarePipeline# } static Void contributeMiddleware(Configuration conf) { conf.set("AuthMiddleware", conf.autobuild(AuthMiddleware#), ["before: Routes"]) }