I asked the discussion in the discussion group , and they helped me achieve this initial version.
I am creating a PrefixedRequest similar to this
import play.api.mvc.RequestHeader import play.api.Play.configuration import play.api.Play.current class PrefixedRequest(request: RequestHeader) extends RequestHeader { def headers = request.headers def queryString = request.queryString // strip first part of path and uri if it matches http.path config def path = ("^" + prefix).r.replaceFirstIn(request.path, "/") def uri = ("^" + prefix).r.replaceFirstIn(request.uri, "/") def method = request.method def remoteAddress = request.remoteAddress lazy val prefix = { val config = configuration.getString("http.path").getOrElse("") if (config.endsWith("/")) config else config + "/" } } object PrefixedRequest { def apply(request: RequestHeader) = new PrefixedRequest(request) }
Then I used it in Global.scala
import play.api.GlobalSettings import play.api.mvc.RequestHeader import play.api.mvc.Handler object Global extends GlobalSettings { override def onRouteRequest(request: RequestHeader): Option[Handler] = { super.onRouteRequest(PrefixedRequest(request)) } }
The finale added this to application.conf
http.path=/prefix/
This seems to work, but I can't find out how to add this prefix to the return routes ... can anyone give a hand for this part?
-
Some useful links
Check out this thread and docs
opensas
source share