Merge remote-tracking branch 'origin/master' into feature/toggle-all-formblock-fields

This commit is contained in:
Dean 2023-11-09 08:46:05 +00:00
commit 68c06e0d72
3 changed files with 42 additions and 33 deletions

View File

@ -27,6 +27,10 @@ interface KoaRateLimitOptions {
} }
const PREFIX = "/api/public/v1" const PREFIX = "/api/public/v1"
// type can't be known - untyped libraries
let limiter: any, rateLimitStore: any
if (!env.DISABLE_RATE_LIMITING) {
// allow a lot more requests when in test // allow a lot more requests when in test
const DEFAULT_API_REQ_LIMIT_PER_SEC = env.isTest() ? 100 : 10 const DEFAULT_API_REQ_LIMIT_PER_SEC = env.isTest() ? 100 : 10
@ -37,7 +41,6 @@ function getApiLimitPerSecond(): number {
return parseInt(env.API_REQ_LIMIT_PER_SEC) return parseInt(env.API_REQ_LIMIT_PER_SEC)
} }
let rateLimitStore: any = null
if (!env.isTest()) { if (!env.isTest()) {
const { password, host, port } = redis.utils.getRedisConnectionDetails() const { password, host, port } = redis.utils.getRedisConnectionDetails()
let options: KoaRateLimitOptions = { let options: KoaRateLimitOptions = {
@ -61,17 +64,22 @@ if (!env.isTest()) {
}) })
} }
// rate limiting, allows for 2 requests per second // rate limiting, allows for 2 requests per second
const limiter = RateLimit.middleware({ limiter = RateLimit.middleware({
interval: { sec: 1 }, interval: { sec: 1 },
// per ip, per interval // per ip, per interval
max: getApiLimitPerSecond(), max: getApiLimitPerSecond(),
}) })
} else {
console.log("**** PUBLIC API RATE LIMITING DISABLED ****")
}
const publicRouter = new Router({ const publicRouter = new Router({
prefix: PREFIX, prefix: PREFIX,
}) })
if (limiter) {
publicRouter.use(limiter) publicRouter.use(limiter)
}
function addMiddleware( function addMiddleware(
endpoints: any, endpoints: any,

View File

@ -61,6 +61,7 @@ const environment = {
ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS, ALLOW_DEV_AUTOMATIONS: process.env.ALLOW_DEV_AUTOMATIONS,
DISABLE_THREADING: process.env.DISABLE_THREADING, DISABLE_THREADING: process.env.DISABLE_THREADING,
DISABLE_AUTOMATION_LOGS: process.env.DISABLE_AUTOMATION_LOGS, DISABLE_AUTOMATION_LOGS: process.env.DISABLE_AUTOMATION_LOGS,
DISABLE_RATE_LIMITING: process.env.DISABLE_RATE_LIMITING,
MULTI_TENANCY: process.env.MULTI_TENANCY, MULTI_TENANCY: process.env.MULTI_TENANCY,
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
SELF_HOSTED: process.env.SELF_HOSTED, SELF_HOSTED: process.env.SELF_HOSTED,

View File

@ -20,7 +20,7 @@
"test:self:ci": "yarn run test --testPathIgnorePatterns=\\.integration\\. \\.cloud\\. \\.licensing\\.", "test:self:ci": "yarn run test --testPathIgnorePatterns=\\.integration\\. \\.cloud\\. \\.licensing\\.",
"serve:test:self:ci": "start-server-and-test dev:built http://localhost:4001/health test:self:ci", "serve:test:self:ci": "start-server-and-test dev:built http://localhost:4001/health test:self:ci",
"serve": "start-server-and-test dev:built http://localhost:4001/health", "serve": "start-server-and-test dev:built http://localhost:4001/health",
"dev:built": "cd ../ && yarn dev:built" "dev:built": "cd ../ && DISABLE_RATE_LIMITING=1 yarn dev:built"
}, },
"devDependencies": { "devDependencies": {
"@budibase/types": "^2.3.17", "@budibase/types": "^2.3.17",