Jon
Jon

Reputation: 168

express-rate-limit with static

I have VPS with express and react bundle. The problem is that I get the same IP address (localhost) when I access the API from the frontend, therefore I cannot correctly use the express-rate-limit.

I have an express server:

const apiLimiter = rateLimit({
  windowMs: 1 * 60 * 1000,
  max: 30
});

app.use("/api/", apiLimiter);

app.use(express.static('client/build'));
app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'));
});

and proxy config in package.json of frontend:

"proxy": "http://localhost:3000/"

How to fix it and use express-rate-limit correctly?

Upvotes: 5

Views: 668

Answers (1)

Michael Hobbs
Michael Hobbs

Reputation: 1693

Per https://www.npmjs.com/package/express-rate-limit#usage

app.set('trust proxy', 1)

Upvotes: 2

Related Questions