Ben DechraiB
Denoβ€’2y agoβ€’
2 replies
Ben Dechrai

Getting the client IP address with `deno serve`

I'm trying to get the IP address of the client when running declarative scripts through deno serve.

It seems the fetch method only accepts the first request parameter, and if I expect and address the connInfo parameter, I get an Internal Server Error and a console output of TypeError: Cannot read properties of undefined (reading 'remoteAddr').

Are declarative scripts intended to not have access to this additional information? Or have I overlooked something?

export default {
  async fetch(request, connInfo) {
    const clientIP = connInfo.remoteAddr.hostname;
    return new Response(`Hello world! Your IP address is ${clientIP}`);
  },
};


Cheers,
Ben
Was this page helpful?