【发布时间】:2022-01-16 23:57:32
【问题描述】:
我在单独的文件中定义了我的路线:
PostRoutes.kt:
fun Route.getPostsRoute() {
get("/posts") {
call.respondText("Posts")
}
}
// Some other routes
fun Application.postRoutes() {
routing {
getPostsRoute()
// Some other routes
}
}
我在 Application.kt 中设置了这些路由,如下所示:
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)
fun Application.module(testing: Boolean = false) {
routing { // I want to provide the root endpoint (/api/v1) here
postRoutes()
}
}
在这种情况下如何设置我的根端点 (/api/v1)?
PS我检查了他们的文档,它说要使用嵌套的 routes,但我不能,因为我需要在 postRoutes() 中调用 routing,这会破坏嵌套路由。
P.P.S.我是 Ktor 和 Kotlin 的菜鸟。
【问题讨论】: