Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not able to Implement Rate Limit

See original GitHub issue

I am trying to implement rate limiting in fast-gateway but I am not able to use it since it expects the req.ip object which I believe is not available with fast-gateway. Does that mean I need to import express and create app just to do rate-limiting?

It’d be great if someone pointed out some examples to get me started.

Just used the sample code to get started:

const gateway = require('fast-gateway')
const PORT = process.env.PORT || 9090

const service = gateway({
  middlewares: [
  // Can add routes here!
  routes: [{
    prefix: '/verify',
    target: process.env.VERIFICATION_API

service.start(PORT).then(server => {
  	console.log(`API Gateway listening on ${PORT} port!`)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

jkyberneeescommented, Nov 22, 2019

Hi @rajkumarpb, next I describe a full example:


const gateway = require('../index')
const rateLimit = require('express-rate-limit')
const requestIp = require('request-ip')

  middlewares: [
    // acquire request IP
    (req, res, next) => {
      req.ip = requestIp.getClientIp(req)
      return next()
    // rate limiter
      windowMs: 1 * 60 * 1000, // 1 minutes
      max: 60, // limit each IP to 60 requests per windowMs
      handler: (req, res) => {
        res.send('Too many requests, please try again later.', 429)
  routes: [{
    prefix: '/public',
    target: 'http://localhost:3000'
}).start(8080).then(() => console.log('API Gateway listening on 8080 port!'))

Remote Service:

const service = require('restana')({})
  .get('/hi', (req, res) => res.send('Hello World!'))
  .start(3000).then(() => console.log('Public service listening on 3000 port!'))

Please let me know if it works for you now?


jkyberneeescommented, Nov 22, 2019

I will provide you more feedback here ASAP

Read more comments on GitHub >

github_iconTop Results From Across the Web

Application unable to work due to rate limiter - Stack Overflow
I have tried to implement rate limiter on server.js but it gives this error below making the website crash. Did I implement the...
Read more >
Understanding and implementing rate limiting in Node.js
Explore the concept of rate limiting in Node.js — what it is, how it works, various ways to implement it, and some practical...
Read more >
Rate-limiting strategies and techniques - Google Cloud
When the capacity of a service is shared among many users or consumers, it can apply rate limiting per user to provide fair...
Read more >
How to avoid hitting rate limits in API integration -
We'll go through different API rate limiting techniques as well as strategies and workarounds to recover from them or generally avoid them.
Read more >
Implement API rate limiting to reduce attack surfaces
Rate limiting can help developers prevent APIs from being overwhelmed with requests, thus preventing denial-of-service attacks. Learn how to implement rate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found