I’m creating a middleware and I’m wondering if I c...
# ktor
d
I’m creating a middleware and I’m wondering if I could make
call
available from it ? :
Copy code
fun Application.hasSignedUrlMiddleware() {
    routing {
        val uri = call.request.uri
//        if(url doesn't have a signed url) {
//            throw AuthorizationException("Sorry you are not authorized")
//        }
    }
}
Copy code
get("/posts") {
            hasSignedUrlMiddleware()
            call.respond(mapOf("posts" to postDAO.all()))
        }
a
It doesn't look like middleware. Could you please describe your problem?
d
basically I want something (I call them middlewares) to perform some actions ASAP when a request enters a route (maybe restrict access to a route). But I’d need to be able to access the
call
object (the request) from it . Because I need to get the inputs/parameters from the request to build my logic.
a
You can do something similar to this https://stackoverflow.com/questions/70221688/how-to-restrict-route-access-in-ktor-framework/70338385#70338385. In the route's interceptor you have an access to the
ApplicationCall
object.
👍 1
d
Look interesting. I’ll try it out later 🙂