You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,38 @@ By using the `proxyHandler` hook, developers can optionally intercept and modify
153
153
154
154
Please see the `demos/circuitbreaker.js` example for more details using the `opossum` library.
155
155
156
+
## Rate Limiting
157
+
[Rate limiting](https://en.wikipedia.org/wiki/Rate_limiting), as well many other gateway level features can be easily implemented using `fast-gateway`:
158
+
```js
159
+
constrateLimit=require('express-rate-limit')
160
+
constrequestIp=require('request-ip')
161
+
162
+
gateway({
163
+
middlewares: [
164
+
// first acquire request IP
165
+
(req, res, next) => {
166
+
req.ip=requestIp.getClientIp(req)
167
+
returnnext()
168
+
},
169
+
// second enable rate limiter
170
+
rateLimit({
171
+
windowMs:1*60*1000, // 1 minutes
172
+
max:60, // limit each IP to 60 requests per windowMs
173
+
handler: (req, res) =>res.send('Too many requests, please try again later.', 429)
174
+
})
175
+
],
176
+
177
+
// your downstream services
178
+
routes: [{
179
+
prefix:'/public',
180
+
target:'http://localhost:3000'
181
+
}, {
182
+
// ...
183
+
}]
184
+
})
185
+
```
186
+
> In this example we have used the [express-rate-limit](https://www.npmjs.com/package/express-rate-limit) module.
187
+
156
188
## Gateway level caching
157
189
Caching support is provided by the `http-cache-middleware` module. https://www.npmjs.com/package/http-cache-middleware
0 commit comments