Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I intercept all controller requests in Play 2 + Scala?

In the Java flavor of Play 2, there is GlobalSettings.onRequest, which can be used to intercept all incoming requests to controllers. But in the Scala equivalent, there is no onRequest handler.

I suspect this is because the Action delegation logic needed in Java isn't required in Scala, but it's rather annoying because I want to run some code on every incoming controller request.

Does anyone know how to intercept all controller requests in a Scala + Play 2 app?

like image 374
Patrick Lightbody Avatar asked Feb 17 '23 23:02

Patrick Lightbody


1 Answers

override def onRouteRequest (request: RequestHeader): Option[Handler] in your Global object might be the answer you're looking for.

From the 2.0.4 api, it's called when an HTTP request has been received.

like image 133
evan123 Avatar answered Feb 20 '23 20:02

evan123