Node Express : Does limiting the amount of requests with express-rate-limit work without wifi but with cellular network ip on mobile device?

48 views Asked by At

Im wondering if user has no wifi and is only using his cellular network on his mobile device, the rate limiting will work / will there be a req.ip ?

const rateLimit = require('express-rate-limit')

const apiLimiter = rateLimit({
    windowMs: 15 * 60 * 1000, // 15 minutes
    max: 1, //this number is just for testing
    standardHeaders: true
    legacyHeaders: false, 
    keyGenerator: (req, res) => {
        return req.ip
    },
    handler: function(req, res, next) {
        throw new BaseError('too many requests', 429);
        next();
    },
})
1

There are 1 answers

0
BGPHiJACK On

If a user is accessing your server over their cellular network on a mobile device, the rate limiting will still work, and the req.ip property will be available.

The IP will change however if they switch networks so their limit resets.