@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
24 lines (23 loc) • 768 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRemoteAddress = getRemoteAddress;
/**
* Tries to get the remote address (ip) from the context of a Hono request.
*/
function getRemoteAddress(c) {
// Node.js server
// https://github.com/honojs/node-server/blob/fc749268c411bfdd7babd781cee5bdfed244f1c0/src/conninfo.ts#L10
if (c.env) {
try {
const bindings = c.env.server ? c.env.server : c.env;
const addressInfo = bindings.incoming.socket.address();
if ("address" in addressInfo && typeof addressInfo.address === "string") {
return addressInfo.address;
}
}
catch {
// Ignore
}
}
return undefined;
}