Day 18: Load middleware conditionally

Home DE Day 18: Load middleware conditionally

I’ve introduced a couple of middleware components. Some of them are useful and could be enabled globally, while others might be better enabled on certain conditions. Today we’ll talk about a solution to this. ### Load middleware conditionally Conditional middleware is a super (or meta) middleware that takes one middleware and enable that middleware based on a runtime condition. Let’s take some examples: * You want to enable [JSONP middleware](http://advent.plackperl.org/2009/12/day-16-adding-jsonp-support-to-your-app.html) only if the path begins with /public * You don’t want to enable [Basic Auth](http://advent.plackperl.org/2009/12/day-15-authenticate-your-app-with-middleware.html) if the request comes from local IP We investigated how they deal with situations like…

Source : http://advent.plackperl.org/2009/12/day-18-load-middleware-conditionally.html

Leave a Reply

Your email address will not be published.