Problem getting akrabat/rka-ip-address-middleware to work

I’ve integrated akrabat/rka-ip-address-middleware into my project, but I can’t get it work. Maybe someone here knows what I’m doing wrong. My middleware integration code looks like this:

$checkProxyHeaders = true;
$trustedProxies = [];
$app->add (new RKA\Middleware\IpAddress($checkProxyHeaders, $trustedProxies));

$app->add (function ($request, $response, $next) use ($app) {
    $container = $app->getContainer();
    $settings = $container->get('settings');
    $ipClient  = $request->getAttribute('ip_address');
    // Do something with $ipClient here ...

    $response = $next($request, $response);
    return $response;

The problem I’m having that $ipClient is always returned as null. I’m guessing I’m making some stupid mistake, but I’m just not seeing it. Thanks for any hints & tips.

FILE first in last executed. Add IP middleware after the middleware you use ip in.

BTW; you know that within closure middleware $this === $container? No need to get the container from App.

1 Like

Thank you very much for both tips. I didn’t know either of them. I’ll give them a try later today.

Both your tips/suggestions work like a charm. Thanks a lot!