joel truher
joel truher

Reputation: 748

Play Framework 2.0 multiple static routes

I'm trying to set up two different static asset routes, and the second one fails. What am I missing?

To duplicate the issue:

  1. start with the hello world from the scala samples.

  2. add a line to routes, so now there are two static routes:

    GET     /assets/*file       controllers.Assets.at(path="/public", file)
    GET     /assets2/*file      controllers.Assets.at(path="/public2", file)
    
  3. comment out the Assets references in main.scala.html, so it doesn't complain about them

  4. put a file in public and public2.

    $ cat > public/foo.txt
    hi
    $ mkdir public2
    $ cp public/foo.txt public2
    
  5. verify that the public dir works.

    $ 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. verify that the second one doesn't work.

    $ 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.
    

I'm sure there's something obvious here, I"m just not seeing it.

Upvotes: 4

Views: 2769

Answers (1)

4e6
4e6

Reputation: 10776

You should add public2 folder to playAssetsDirectories in sbt config

playAssetsDirectories <+= baseDirectory / "public2"

See PlaySettings as an example.

Upvotes: 5

Related Questions