我有一个文件夹
root
包含一个
index.html
以及其他资源,如
.css
文件夹。
现在,我正在尝试在托管此文件夹
localhost:8080/test
使用AKKA HTTP路由(
myRoute
)以下。另外,我想在
localhost:8080
. 我还希望带有尾随斜杠的URI重定向到非斜杠的URI(
本地主机:8080/测试
应该等于
localhost:8080/test/
)
不知何故,我无法做到这一点。Hello World页工作正常,但文件夹未托管。我得到的只是一个
The requested resource could not be found.
信息(铬合金)。
def route: Route = {
redirectToNoTrailingSlashIfPresent(StatusCodes.Found) {
(pathSingleSlash {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, homeHtml)) // "hello world"
}
}
~
pathPrefix("test") {
getFromDirectory("root") // contains the index.html
})
}
}
编辑:
当我尝试使用
getFromFile(webDir + "/index.html")
而不是
getFromDirectory(webDir)
(
webDir
存在
根
)
索引文件
已加载,但无法访问css/js文件。