[tink_web] How to access the client IP in a route?

The client’s IP address is available in the request object… but how do you access the request object in a route? It seems that the request object is only available in the Container.run() handler…

I think you can just inject the context into the route:

Thanks @Michael : injecting the Context works. But note that it is necessary to specify the @:privateAccess metadata because the Context.request property is private :slightly_frowning_face:

@:get
function someRoute(ctx: tink.web.routing.Context) {
  final ipAddress = @:privateAccess ctx.request.clientIp;
  // ... return the response
}
1 Like

Maybe @back2dos or @kevinresol will be able to shed some light on this