Created
February 19, 2024 20:31
-
-
Save vcxp/082230592d3cb21d97a23767368ce13c to your computer and use it in GitHub Desktop.
Simple way to get IP-address from request in Express.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async getMyIp(req: Request, res: Response) { | |
const ip = | |
req.headers["cf-connecting-ip"] || | |
req.headers["x-real-ip"] || | |
req.headers["x-forwarded-for"] || | |
req.socket.remoteAddress || ""; | |
return res.status(200).send({ip}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment