Hello! Is this correct configuration for handling ...
# ktor
r
Hello! Is this correct configuration for handling unknown paths in Ktor? We use tomcat on production, but when Ktor receives GET request for unknown path then it returns 200 (only on Tomcat, on localhost it is 404). I used it as workaround and it works great, but I wanted to ask if there is any other way, or maybe if this code is somehow dangerous:
t
Status pages should be used as to handle these situations as far I'm aware of. It should be able to handle response for paths that don't exist: https://ktor.io/docs/server-status-pages.html#status
r
Yes, it works on local, but not on production. Most likely its related to tomcat or other proxy, but still Ktor is receiving calls, so it should automatically somehow answer to proxy that it could not find given path, weird 😞
t
If Ktor is returning correct response, you'll have to check how Tomcat is configured as you said, if any filter is interfering or check how it handles the response from Ktor.
l
We implemented similar (404 on unknown routes) by introducing a route with tailcard ( https://ktor.io/docs/server-routing.html#tailcard ) as the last route:
Copy code
// <https://ktor.io/docs/server-routing.html#tailcard>
    route("{...}") {
        // Handler for any method and path
        handle {
            call.respond(status = HttpStatusCode.NotFound, message = "Nothing to see here!")
        }
    }
As suggested here: https://youtrack.jetbrains.com/issue/KTOR-3028/Servlet-containers-return-200-OK-for-unmapped-route
r
Thanks!!