Ben Dechrai
Ben Dechrai
DDeno
Created by Ben Dechrai on 6/4/2024 in #help
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}`);
},
};
export default {
async fetch(request, connInfo) {
const clientIP = connInfo.remoteAddr.hostname;
return new Response(`Hello world! Your IP address is ${clientIP}`);
},
};
Cheers, Ben
3 replies