exports.prodform=function (req, res) { let phone=req.body.phone; let province=req.body.province; let city=req.body.city; let district=req.body.district; let detailaddress=req.body.detailaddress; let data= " 手机号码: "+phone+" 地址: "+province+city+district+detailaddress+'\r\n'; let json={ "success":true, } fs.writeFile("订单.txt",data,{flag: 'a'},function(err,result) { if(err) throw err; console.log('成功'); }) res.json(json);}对于上面这个接口,我如何统计不同ip地址对其的访问次数呢?
1 回答
湖上湖
TA贡献2003条经验 获得超2个赞
定义一个全局变量
例如 ipList = {};
在exports.prodform里面加入下面的代码:
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
if(!!ipList[ip]){
ipList[ip] = ipList[ip]+1;
}else{
ipList[ip] = 1;
}
或者使用redis吧
添加回答
举报
0/150
提交
取消