Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/disable ratelimit #710

Merged
merged 2 commits into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions packages/sdk-socket-server/src/api-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Analytics from 'analytics-node';
import bodyParser from 'body-parser';
import cors from 'cors';
import express from 'express';
import { rateLimit } from 'express-rate-limit';
import helmet from 'helmet';
import { createClient } from 'redis';
import { logger } from './logger';
Expand All @@ -18,13 +17,34 @@ const THIRTY_DAYS_IN_SECONDS = 30 * 24 * 60 * 60; // expiration time of entries

const app = express();

const limiter = rateLimit({
windowMs: 5 * 60 * 1000, // 5 minutes
limit: 100, // Limit each IP to 100 requests per `window` (here, per 5 minutes).
standardHeaders: 'draft-7', // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
// store: ... , // Use an external store for consistency across multiple server instances.
});
// FIXME enable correctly
// let windowMsNum = 1;
// try {
// if (process.env.REDIS_HTTP_WINDOW_MS_NUM) {
// windowMsNum = parseInt(process.env.REDIS_HTTP_WINDOW_MS_NUM, 16);
// }
// } catch (err) {
// logger.warn(
// `Invalid REDIS_HTTP_WINDOW_MS_NUM env: ${process.env.REDIS_HTTP_WINDOW_MS_NUM}`,
// );
// }

// let httpLimit = 10_000_000;
// try {
// if (process.env.REDIS_HTTP_LIMIT) {
// httpLimit = parseInt(process.env.REDIS_HTTP_LIMIT, 16);
// }
// } catch (err) {
// logger.warn(`Invalid REDIS_HTTP_LIMIT env: ${process.env.REDIS_HTTP_LIMIT}`);
// }

// const limiter = rateLimit({
// windowMs: windowMsNum * 60 * 1000, // 1 minutes
// limit: httpLimit, // Limit each IP to 10000000 requests per `window` (here, per 5 minutes).
// standardHeaders: 'draft-7', // draft-6: `RateLimit-*` headers; draft-7: combined `RateLimit` header
// legacyHeaders: false, // Disable the `X-RateLimit-*` headers.
// // store: ... , // Use an external store for consistency across multiple server instances.
// });

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
Expand All @@ -33,7 +53,7 @@ app.options('*', cors());
app.use(helmet());
app.disable('x-powered-by');
// Apply the rate limiting middleware to all requests.
app.use(limiter);
// app.use(limiter);

async function inspectRedis(key?: string) {
if (key && typeof key === 'string') {
Expand Down
Loading