Reputation: 1202
I have a scala play microservice and I am trying to redirect to an external url. But I have problem because the redirect url is being appended to the domain of the service. My code is:
Redirect("www.google.com", 302)
But when I run my controller method in the browser it tries to redirect to this url
http://localhost:9000/www.google.com
and it complains telling me that there is no end point defined in the router with
Action Not Found
GET /www.google.com
How can I make it redirect to just www.google.com?
UPDATE
I have managed to get it working as follows:
set a route as follows
GET /google controllers.Default.redirect(to = "http://google.com")
and in the controller I change the redirect to:
Redirect("google", 302)
I'm not sure what the pros and cons are of this solution. How is redirect to external URLs supposed to work in Play? Also this doesn't work for me as I don't want to code in the endpoints. For my use case, the redirect url is dynamic. It can be whatever the user supplies to my service.
Upvotes: 0
Views: 552
Reputation: 157
This worked for me in Scala:
package controllers
import play.api.mvc.{Action, Controller}
object essai extends Controller{
def toGoogle() = Action {
Redirect("http://google.com", 302)
}
}
Upvotes: 2