Playframework 2.0 覆盖播放资源的反向路由器

Playframework 2.0 覆盖播放资源的反向路由器,playframework-2.0,Playframework 2.0,我正在处理一个播放应用程序,我想覆盖。考虑page.scala.html中的以下代码: <link rel="stylesheet" href='@controllers.routes.Assets.at("stylesheet/main.css")'> 这可能吗 解决方案 我使用了一种模拟反向路由器行为的自定义方法: def reverseAt(file: String): Call = { val prefix = if (basepath.isEmpty) _prefix

我正在处理一个播放应用程序,我想覆盖。考虑page.scala.html中的以下代码:

<link rel="stylesheet" href='@controllers.routes.Assets.at("stylesheet/main.css")'>
这可能吗

解决方案

我使用了一种模拟反向路由器行为的自定义方法:

def reverseAt(file: String): Call = {
  val prefix = if (basepath.isEmpty) _prefix + { _defaultPrefix } + "assets/" else basepath

  (file: @unchecked) match {
    case (file) if file == "robots.txt" => Call("GET", prefix + "robots.txt")
    case (file) if true => Call("GET", prefix + implicitly[PathBindable[String]].unbind("file", file))

}

由于您实际上不会执行到远程主机的任何路由(即,不提供实际响应),因此没有任何理由乱搞路由控制器。您可以创建一个助手对象,该对象执行与反向资源路由器相同的操作,必要时调用实际的反向资源路由器

object Assets {
    val staticHost = scala.util.Properties.envOrElse("staticHost","")

    def at(path: String): String = {
        if (staticHost.isEmpty)
            controllers.routes.Assets.at(file).url
        else
            staticHost + file
    }

}

你好,林布群。谢谢你的建议。我最终找到了反向代理的源代码,然后在自定义方法中使用了相同的方法
object Assets {
    val staticHost = scala.util.Properties.envOrElse("staticHost","")

    def at(path: String): String = {
        if (staticHost.isEmpty)
            controllers.routes.Assets.at(file).url
        else
            staticHost + file
    }

}