我在Scala上实现一个简单的Web服务器与AKK http路由DSL等。我有(例如):Akka HTTP响应HTML字符串与循环的CSS或图像链接
val route = get {
path("test") {
complete((new ViewTemplate).response)
}
}
凡ViewTemplateis类谁读一些HTML模板,一些价值注入它可能使一些转换和收益作为HttpResponse对象...
class ViewTemplate(val filename: String = "test.html") {
import scala.io.Source
private val template = Source.fromResource(filename)
override def toString: String = template.mkString
def entity: ResponseEntity = HttpEntity(ContentTypes.`text/html(UTF-8)`, toString)
def response: HttpResponse = HttpResponse(entity = entity)
}
这一切的作品直到我加入
<link rel="stylesheet" href="style.css"/>
into test.html的头部。浏览器完全忽略了这个参考。与图像和a的东西相同的情况。我想,像游戏喷剂这样的事情处理这种情况很好,我正在发明另一辆自行车,但我只是在寻找根。那么你有什么建议?
这个问题已经关闭。 getFromResourceDirectory(“”)发挥了魔力。 –