Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 1 Examples of "rate-limit-mongo in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'rate-limit-mongo' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

// 开发环境生产,在控制台打印出请求记录
// if (config.debug) app.use(logger('dev'));

// http://www.cnblogs.com/vipstone/p/4865079.html
app.use(bodyParser.json({limit: '20mb'}));
app.use(bodyParser.urlencoded({limit: '20mb', extended: true}));

app.use(cookieParser(config.cookieSecret));
// 可以支持X-Forwarded-Proto(协议代理) X-Forwarded-For(ip代理), X-Forwarded-Host(主机代理)
app.set('trust proxy', 1);

if (!config.debug) {
	// [所有请求]限制每个ip,一小时最多1500次请求
	app.use(rateLimit({
		store: new MongoStore({
			uri: config.mongodbURI,
			expireTimeMs: 60 * 60 * 1000
		}),
		windowMs: 60 * 60 * 1000,
		max: 1500,
		skip: (req: any, res: any) => {

      // 获取客户端请求ip
      let ip;
      
      if (req.headers['x-forwarded-for']) {
        ip = req.headers['x-forwarded-for'].toString().split(",")[0];
      } else {
        ip = req.connection.remoteAddress;
			}

Is your System Free of Underlying Vulnerabilities?
Find Out Now