2012-04-17 81 views
4

我試圖設置兩個不同的靜態資產路由,第二個失敗。我錯過了什麼?Play Framework 2.0多個靜態路由

要複製的問題:

  1. 開始從斯卡拉樣品的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. 公開和公開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. 
    

我敢肯定有一些東西很明顯這裏,我「米只是沒有看到它。

回答

5

你應該public2文件夾中的SBT配置添加到playAssetsDirectories

playAssetsDirectories <+= baseDirectory/"public2" 

PlaySettings作爲一個例子。

+0

哦,我的上帝,固定。謝謝。 – 2012-04-17 14:19:17

+3

我加對維基的一點點,以便爲後代保留一段時間。 https://github.com/playframework/Play20/wiki/Assets – 2012-04-17 14:21:57

+0

您可以更具體地瞭解PlaySettings將如何提供幫助? PlaySettings中沒有字符串「playAssetsDirectories」或「baseDirectory /」。謝謝 – 2014-04-24 19:24:31