Search code examples
koa

When Running Koa Server Locally Request IP Address is ::1


I am running a Koa server locally and when I log the IP of an incoming request the value shows up as ::1, which is the IP address of the local server. How do I get it to log the IP address of the user that made the request?

I am trying to get the user's IP like this:

app.use(async (ctx, next) => { console.log(ctx.request.ip); });


Solution

  • If you got ::1 then this is literally the IP address of the HTTP client that made the request. ::1 is the localhost address when using ipv6.

    If you make the request from somewhere else, the ip will be different.