I have a Play Framework app running on Heroku, using Heroku's SSL endpoint.
I would like to make all pages available via SSL
only.
What's the best way to that?
So far, my best solution is to use onRouteRequest
in my GlobalSettings
and route non-SSL
requests to a special redirect handler:
override def onRouteRequest(request: RequestHeader): Option[Handler] = {
if (Play.isProd && !request.headers.get("x-forwarded-proto").getOrElse("").contains("https")) {
Some(controllers.Secure.redirect)
} else {
super.onRouteRequest(request)
}
}
and
package controllers
import play.api.mvc._
object Secure extends Controller {
def redirect = Action { implicit request =>
MovedPermanently("https://" + request.host + request.uri)
}
}
Is there a way to do this entirely from within GlobalSettings
? Or something even better?