Ordering Rack Middleware Rails Application
Rack middleware is a simply bigger thing then rails. It’s look-alike rack application that you can use to filter, process, or otherwise mess with responses.There is middleware like warden - devise, to work on catch and log exceptions, deal with cookies, SSO, and pretty much anything else you can think of. And in case you missed it, rails is a rack application. Create a new rails app and run
It will display results like this :
Okay so what’s the problem?
let’s you have an middleware say AwesomeMe. The AwesomeMe is calculated after the response time is injected, so that’s fine (imagine if the etag middleware was at the bottom). What about poor ExceptionNotifier? What if there is an exception thrown in the ResponseTimeInjector or AwesomeMe middleware? ExceptionNotifier isn’t going to catch it! The ExceptionNotifier middleware doesn’t modify anything in the response, so it needs to be up higher; it needs to be first.
You can add a new middleware to the middleware stack using any of the following methods:
config.middleware.use(new_middleware, args) - Adds the new middleware at the bottom of the middleware stack.
config.middleware.insert_before(existing_middleware, new_middleware, args) - Adds the new middleware before the specified existing middleware in the middleware stack.
config.middleware.insert_after(existing_middleware, new_middleware, args) - Adds the new middleware after the specified existing middleware in the middleware stack.
And if you get stuck… Ask Here
email me email@example.com