node 获取客户端ip

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/adley_app/article/details/89675336
npm install request-ip
const requestIp = require('request-ip');
 
// inside middleware handler
const ipMiddleware = function(req, res, next) {
    const clientIp = requestIp.getClientIp(req); 
    next();
};
 
// on localhost you'll see 127.0.0.1 if you're using IPv4 
// or ::1, ::ffff:127.0.0.1 if you're using IPv6

猜你喜欢

转载自blog.csdn.net/adley_app/article/details/89675336