Play Framework 2.0多个静态路由

joe*_*her 4 scala routes playframework-2.0

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

要复制此问题:

  1. 从scala样本开始的hello world.

  2. 在路由中添加一行,所以现在有两条静态路由:

    GET     /assets/*file       controllers.Assets.at(path="/public", file)
    GET     /assets2/*file      controllers.Assets.at(path="/public2", file)
    
    Run Code Online (Sandbox Code Playgroud)
  3. 注释掉main.scala.html中的Assets引用,因此它不会抱怨它们

  4. 把文件放在公共场所和公共场所2.

    $ cat > public/foo.txt
    hi
    $ mkdir public2
    $ cp public/foo.txt public2
    
    Run Code Online (Sandbox Code Playgroud)
  5. 验证公共目录是否有效.

    $ 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.
    
    Run Code Online (Sandbox Code Playgroud)
  6. 验证第二个不起作用.

    $ 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.
    
    Run Code Online (Sandbox Code Playgroud)

我相信这里有一些明显的东西,我只是没有看到它.

4e6*_*4e6 5

您应该在sbt config中添加public2文件夹playAssetsDirectories

playAssetsDirectories <+= baseDirectory / "public2"
Run Code Online (Sandbox Code Playgroud)

请参阅PlaySettings作为示例.

  • 我在维基上加了一点,以便为后代留一些时间.https://github.com/playframework/Play20/wiki/Assets (3认同)