DenoDDeno
Powered by
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
deno serve
.

It seems the fetch method only accepts the first
request
request
parameter, and if I expect and address the
connInfo
connInfo
parameter, I get an Internal Server Error and a console output of
TypeError: Cannot read properties of undefined (reading 'remoteAddr')
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}`);
  },
};
export default {
  async fetch(request, connInfo) {
    const clientIP = connInfo.remoteAddr.hostname;
    return new Response(`Hello world! Your IP address is ${clientIP}`);
  },
};


Cheers,
Ben
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

How to get remote IP address when using Deno.serve?
frigjordFfrigjord / help
4y ago
How to serve HTTPS with the Deno.serve() API
ZidanZZidan / help
3y ago
deno serve logs?
Jack MJJack M / help
2y ago
Deno.serve with aws-lambda-adapter
squizSsquiz / help
17mo ago