4

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

要复制问题:

  1. 从 scala 示例中的 hello world 开始。

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

    GET     /assets/*file       controllers.Assets.at(path="/public", file)
    GET     /assets2/*file      controllers.Assets.at(path="/public2", file)
    
  3. 注释掉 main.scala.html 中的资产引用,所以它不会抱怨它们

  4. 将文件放在 public 和 public 2。

    $ cat > public/foo.txt
    hi
    $ mkdir public2
    $ cp public/foo.txt public2
    
  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.
    
  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.
    

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

4

1 回答 1

5

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

playAssetsDirectories <+= baseDirectory / "public2"

以 PlaySettings为例。

于 2012-04-17T06:33:35.763 回答