小编use*_*754的帖子

无法使用 Ktor 提供静态内容

我尝试使用 Route.static 函数来提供静态文件,但它不起作用。我在工作目录中尝试了各种组合和文件夹。现在我在resources/static/css下有一个css,在resources/static下有一个index.html。如果我写以下内容,我不会得到任何服务:

@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {

    val client = HttpClient(Apache) {}

    routing {
      static("root") {
        files("css")
        default("index.html")
      }
   }
}
Run Code Online (Sandbox Code Playgroud)

但是,我可以根据这个答案:Ktor - Static contentrouting,写:

        resource("/", "index.html")
        resource("*", "index.html")
Run Code Online (Sandbox Code Playgroud)

然后我会在resources/static下得到index.html。然而我无法得到任何其他东西。我在这里做错了什么?

参考: https: //ktor.io/servers/features/static-content.html#specifying-files-and-folders

kotlin ktor

5
推荐指数
1
解决办法
3024
查看次数

标签 统计

kotlin ×1

ktor ×1