Is it possible to run some controllers and routes only in test mode?
I need to mock some response when clicking by link. I would create controller and routs that would be available only when I run play test.
Is it possible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Mike has indicated, the code from my Blog indeed shows you how to configure your route file, so that only certain routes are available in Dev or Prod mode. So…
However, this will indeed prevent these routes from working in Prod mode, but they will not exclude the controller from being accessed. The reason for this, is that more than likely you will have the following at the bottom of your routes file
This means that I can access the
Application.noProdaction using the catch all route, which would be the following URLSo. If you want to hide your routes and your controllers, you have a few options.
You could remove the catch-all route, so that there is no entry other than the specific routes you have set up. This does mean that you need to specify all your routes for all actions in your routes file.
Secondly, you could check for
play.mode.isDev()in your actions, and callbadRequest()to prevent access. This would make this much more visible, but may be an unacceptable overhead in coding.