sbilstein
sbilstein

Reputation: 307

Conditional routes/routing and Play 2.0

In Play1.x it was possible to define some conditional routes using the following syntax:

%{ if (play.id == "test") }%

GET     /test/derp website.nonproduction.DerpController.index
...

The %{...}% syntax does not compile on Play2 and I cannot seem to find anything in the documentation that discusses conditional routing. Any ideas?

Thanks in advance & good luck with your Play2 migrations!

Upvotes: 3

Views: 734

Answers (1)

Andrew Conner
Andrew Conner

Reputation: 1436

Routing in Play 2.0 compiles to a class and cannot be dynamic. However, you can wrap the Action block of any development / sensitive endpoints.

You can implement something like Zentasks's Secured trait: https://github.com/playframework/Play20/blob/master/samples/scala/zentasks/app/controllers/Application.scala

Specifically, to check if Play! is running in Production mode, you can check Play.application().isProd.

Upvotes: 3

Related Questions