Spray.io不响应css文件

时间:2014-05-27 11:22:14

标签: spray

我有一个喷涂应用程序。

 //src/main/resources/twirl/app/index.scala.html 
 <!DOCTYPE html>
 <html>

   <head lang="en">
     <meta charset="UTF-8">
     <title></title>
     <link rel="stylesheet" href="css/file.css" />
   </head>
   <body>
     ...
   </body>
 </html>

src/main/resources/css/file.css我的带有样式的css文件中。

我的服务:

 //src/main/scala/app/service.scala
 trait MyRoute extends HttpService {
   val route = pathPrefix("") {
     get {
       respondWithMediaType(`text/html`) {
         complete {
           app.html.index.render
         }
       }
     }
  } ~
  pathPrefix("css") {
    get {
      getFromResourceDirectory("css")
    }
  }

  class MyActor extends Actor with MyRoute {
    def actorRefFactory = context
    def receive = runRoute(route)
  }

  //main app
  object Main extends App {
   implicit val system = ActorSystem("app")
   val service = system.actorOf(Props[MyActor], "my-service")

   IO(Http) ! Http.Bind(service, "localhost", port = 8080)
  }

当我运行此应用程序时,我进入了chrome控制台:Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost:8080/css/file.css".

而不是file.css内容,我得到了index.scala.html内容。如何使用spray.io返回css静态文件?

0 个答案:

没有答案