https://kotlinlang.org logo
#ktor
Title
# ktor
b

Benjamin Schlie

02/05/2021, 4:08 PM
Hi! Is it possible to run two applications on the same server with different StatusPages? I have tried adding two routes to match different hosts and add
install(StatusPages)
in each of them. The routes works, but not the StatusPages.
Copy code
routing {
        header(HttpHeaders.Host, "localhost:8080") {
            route("/") {
                handle {
                    call.respondText("Hello world")
                }
            }
            install(StatusPages) {
                status(HttpStatusCode.NotFound) { status ->
                    call.respondText("Not found!")
                }
            }
        }
    }

    routing {
        header(HttpHeaders.Host, "another-host:8080") {
            route("/") {
                handle {
                    call.respondText("Hello another world")
                }
            }
            install(StatusPages) {
                status(HttpStatusCode.NotFound) { status ->
                    call.respondText("No other world found!")
                }
            }
        }
    }
r

Rustam Siniukov

02/05/2021, 4:38 PM
hi, this is currently not supported, but we are working on it here https://youtrack.jetbrains.com/issue/KTOR-928 it’s expected to be ready in 1.6.0
👍 4
a

Arkangel

02/05/2021, 5:47 PM
this is similar to microservice arch? right
?
s

spand

02/06/2021, 8:56 AM
@Rustam Siniukov Nice! Do you have a no-promises-estimate of when 1.6 will be released? I tried searching but couldnt find a 2021 roadmap.
r

Rustam Siniukov

02/08/2021, 11:54 AM
@spand with current schedule, you can expect 1.6.0 somewhere in April-May. But we also starting to publish EAP where you can try versions that were not released yet https://blog.jetbrains.com/ktor/2021/02/03/say-hello-to-ktor-early-access-program-and-new-plugin/
@Benjamin Schlie looking at it again, status pages may be not intuitive with sub route install. For example, what would you expect here
Copy code
routing {
    header(HttpHeaders.A, "A") {
        get("A") { }
        install(StatusPages) {
            status(HttpStatusCode.NotFound) { status ->
                call.respondText("Not found in A!")
            }
        }
    }
    header(HttpHeaders.B, "B") {
        get("B") { }
        install(StatusPages) {
            status(HttpStatusCode.NotFound) { status ->
                call.respondText("No found in B!")
            }
        }
    }
}
if request is
Copy code
client.get{
  addHeader(Header.A, "A")
  addHeader(Header.B, "B")
  path = "C"
}
Here both sub routes match on headers and have StatusPages installed, but none of them contain required path. My point is even after we support installing features into sub routes, StatusPages may require additional desgin
b

Benjamin Schlie

02/08/2021, 3:06 PM
@Rustam Siniukov I didn't really consider that case since I only look at host-headers. I expected that matching a route without the required path would return me the status page for that route and not looking for other routes. But I see the limitation from your example. As of now, my workaround is to install a "global" StatusPage, and check the call.request header to find the right status page. But I would prefer if my StatusPage handling could be added within the routes.
👍 1
3 Views