scala - Play Framework 2.0 多条静态路由

标签 scala routes playframework-2.0

我正在尝试设置两个不同的静态 Assets 路由,第二个失败了。我错过了什么?

要复制问题:

  • 从 scala 示例中的 hello world 开始。
  • 在路由中添加一行,所以现在有两条静态路由:
    GET     /assets/*file       controllers.Assets.at(path="/public", file)
    GET     /assets2/*file      controllers.Assets.at(path="/public2", file)
    
  • 注释掉 main.scala.html 中的 Assets 引用,所以它不会提示它们
  • 将文件放在 public 和 public 2。
    $ cat > public/foo.txt
    hi
    $ mkdir public2
    $ cp public/foo.txt public2
    
  • 验证公共(public)目录是否有效。
    $ telnet localhost 9000
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /assets/foo.txt HTTP/1.0
    
    HTTP/1.1 200 OK
    Content-Length: 3
    Content-Type: text/plain
    Etag: 5246040afe91a4cc93bd838a4d5db3984b99470b
    Cache-Control: no-cache
    
    hi
    Connection closed by foreign host.
    
  • 确认第二个不起作用。
    $ telnet localhost 9000
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /assets2/foo.txt HTTP/1.0
    
    HTTP/1.1 404 Not Found
    Content-Length: 0
    
    Connection closed by foreign host.
    

  • 我敢肯定这里有一些明显的东西,我只是没看到。

    最佳答案

    您应该添加 public2文件夹到 playAssetsDirectories在 sbt 配置中

    playAssetsDirectories <+= baseDirectory / "public2"
    

    PlaySettings举个例子。

    关于scala - Play Framework 2.0 多条静态路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10185956/

    相关文章:

    scala - 带有 akka : Providing implicit actorSystem to several layers 的蛋糕图案

    php - 在 Laravel 5.0 中限制路由的最佳方法是什么?

    javascript - Scala Play : Concurent. 广播无法与 EventSource 配合使用

    playframework-2.0 - Play 2.0中的session.id在哪里?

    scala - 合并后如何保留两个可观察对象发出的项目的顺序?

    Eclipse:scala 工作表中的 "Output exceeds cutoff limit"

    scala - 如何在 Scala for 循环中指定一个 'next' 函数

    web-services - 指定 Controller 的MapHttpRoute

    php - 在路由中使用连字符 (-) 而不是斜杠 (/) 或下划线 (_)

    oop - 从具有 Id 的数据库中获取对象时,是否使用 Option 作为结果?