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

dany giguere

02/23/2022, 9:45 PM
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

Aleksei Tirman [JB]

02/24/2022, 9:07 AM
It doesn't look like middleware. Could you please describe your problem?
d

dany giguere

02/24/2022, 12:43 PM
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

Aleksei Tirman [JB]

02/24/2022, 12:54 PM
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

dany giguere

02/24/2022, 1:07 PM
Look interesting. I’ll try it out later 🙂
54 Views