Search code examples
dartaqueduct

How to get client remote ip address in resource controller


How can I access request.connectioninfo.remoteaddress in a function of a resourcecontroller? I need to store and log the client remote IP.


Solution

  • Use the raw property of the request https://pub.dartlang.org/documentation/aqueduct/latest/aqueduct/Request/raw.html

    Edit by CA: The request object is already present in a controller that extends from ResourceController or Controller and can simply be used as such:

    final remote_address = request.raw.connectionInfo.remoteAddress.address;