Reputation: 1319
I'm using an Akka Scheduler to make a request to the root url of my Play Framework application every minute to refresh the application's cache if it expires.
At the moment I am calling WS.url("http://127.0.0.1:9000/").get();
as I am working on my localhost. Obviously, when I push to production I will change this to request the production URL.
Is there a function to obtain the root url automatically, so that I don't have to change this each time?
Upvotes: 0
Views: 631
Reputation: 55798
You have 3 solutions, get it from reverse route OR from config OR from both (with config priority):
String reverseRoute = routes.Application.index().absoluteURL(request());
String refreshUrlFromConf = Play.application().configuration().getString("refreshUrl");
String mixed = Play.application().configuration().getString(
"refreshUrl",
routes.Application.index().absoluteURL(request())
);
If you want to use config approach, of course you need to add this to your application.conf
:
refreshUrl = "http://your-instance.tld"
BTW you don't need to refresh cache yourself, it will be refreshed at the very first request, right after cache termination.
Upvotes: 2