mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Temporarily disable caching
This commit is contained in:
@@ -1,83 +0,0 @@
|
||||
import redis from 'redis';
|
||||
import {
|
||||
RateLimiterRedis,
|
||||
RateLimiterMemory,
|
||||
IRateLimiterStoreOptions,
|
||||
IRateLimiterOptions,
|
||||
} from 'rate-limiter-flexible';
|
||||
import { RedisNotFoundException } from '../exceptions';
|
||||
import env from '../env';
|
||||
|
||||
// options for the rate limiter are set below. Opts can be found
|
||||
// at https://github.com/animir/node-rate-limiter-flexible/wiki/Options
|
||||
|
||||
let rateLimiterConfig = new RateLimiterMemory(getRateLimiterConfig());
|
||||
// need to pick redis or memory
|
||||
if (env.RATE_LIMIT_TYPE === 'redis') {
|
||||
rateLimiterConfig = new RateLimiterRedis(getRateLimiterRedisConfig());
|
||||
}
|
||||
|
||||
export default rateLimiterConfig;
|
||||
|
||||
function getRateLimiterConfig(): IRateLimiterOptions {
|
||||
const config: any = {};
|
||||
config.keyPrefix = 'rlflx';
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (key === 'CONSUMED_POINTS_LIMIT') {
|
||||
config.points = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'CONSUMED_RESET_DURATION') {
|
||||
config.duration = value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
function getRateLimiterRedisConfig(): IRateLimiterStoreOptions {
|
||||
const redisConfig: any = {};
|
||||
const redisClient = redis.createClient({
|
||||
enable_offline_queue: false,
|
||||
host: env.REDIS_HOST,
|
||||
port: env.REDIS_PORT,
|
||||
password: env.REDIS_PASSWORD,
|
||||
});
|
||||
|
||||
if (!redisClient) {
|
||||
throw new RedisNotFoundException('Redis client does not exist');
|
||||
}
|
||||
|
||||
redisConfig.keyPrefix = 'rlflx';
|
||||
redisConfig.storeClient = redisClient;
|
||||
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
if (key === 'CONSUMED_POINTS_LIMIT') {
|
||||
redisConfig.points = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'CONSUMED_RESET_DURATION') {
|
||||
redisConfig.duration = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'EXEC_EVENLY') {
|
||||
redisConfig.execEvenly = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'BLOCK_POINT_DURATION') {
|
||||
redisConfig.blockDuration = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'INMEMORY_BLOCK_CONSUMED') {
|
||||
redisConfig.inmemoryBlockOnConsumed = value;
|
||||
continue;
|
||||
}
|
||||
if (key === 'INMEMEMORY_BLOCK_DURATION') {
|
||||
redisConfig.inmemoryBlockDuration = value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return redisConfig;
|
||||
}
|
||||
Reference in New Issue
Block a user