1
0
Fork 0
mirror of synced 2024-08-17 02:51:55 +12:00

Fixing review comments.

This commit is contained in:
mike12345567 2022-03-03 12:03:29 +00:00
parent 1751ebf6ca
commit 69418e9711
4 changed files with 14 additions and 7 deletions

View file

@ -148,6 +148,7 @@
"@types/jest": "^26.0.23", "@types/jest": "^26.0.23",
"@types/koa": "^2.13.3", "@types/koa": "^2.13.3",
"@types/koa-router": "^7.4.2", "@types/koa-router": "^7.4.2",
"@types/koa2-ratelimit": "^0.9.2",
"@types/node": "^15.12.4", "@types/node": "^15.12.4",
"@types/oracledb": "^5.2.1", "@types/oracledb": "^5.2.1",
"@typescript-eslint/parser": "4.28.0", "@typescript-eslint/parser": "4.28.0",

View file

@ -58,7 +58,7 @@ module External {
) { ) {
const primary = table.primary const primary = table.primary
// if passed in array need to copy for shifting etc // if passed in array need to copy for shifting etc
let idCopy = cloneDeep(id) let idCopy: undefined | string | any[] = cloneDeep(id)
if (filters) { if (filters) {
// need to map over the filters and make sure the _id field isn't present // need to map over the filters and make sure the _id field isn't present
for (let filter of Object.values(filters)) { for (let filter of Object.values(filters)) {

View file

@ -9,10 +9,9 @@ import { paramResource, paramSubResource } from "../../../middleware/resourceId"
import { CtxFn } from "./utils/Endpoint" import { CtxFn } from "./utils/Endpoint"
import mapperMiddleware from "./middleware/mapper" import mapperMiddleware from "./middleware/mapper"
import env from "../../../environment" import env from "../../../environment"
import { RateLimit, Stores } from "koa2-ratelimit"
// below imports don't have declaration files // below imports don't have declaration files
const Router = require("@koa/router") const Router = require("@koa/router")
const RateLimit = require("koa2-ratelimit").RateLimit
const Stores = require("koa2-ratelimit").Stores
const { const {
PermissionLevels, PermissionLevels,
PermissionTypes, PermissionTypes,
@ -20,7 +19,14 @@ const {
const { getRedisOptions } = require("@budibase/backend-core/redis").utils const { getRedisOptions } = require("@budibase/backend-core/redis").utils
const PREFIX = "/api/public/v1" const PREFIX = "/api/public/v1"
const DEFAULT_API_LIMITING = 120 const DEFAULT_API_REQ_LIMIT_PER_SEC = 10
function getApiLimitPerSecond(): number {
if (!env.API_REQ_LIMIT_PER_SEC) {
return DEFAULT_API_REQ_LIMIT_PER_SEC
}
return parseInt(env.API_REQ_LIMIT_PER_SEC)
}
if (!env.isTest()) { if (!env.isTest()) {
const REDIS_OPTS = getRedisOptions() const REDIS_OPTS = getRedisOptions()
@ -37,9 +43,9 @@ if (!env.isTest()) {
} }
// rate limiting, allows for 2 requests per second // rate limiting, allows for 2 requests per second
const limiter = RateLimit.middleware({ const limiter = RateLimit.middleware({
interval: { min: 1 }, interval: { sec: 1 },
// per ip, per interval // per ip, per interval
max: env.API_RATE_LIMITING || DEFAULT_API_LIMITING, max: getApiLimitPerSecond(),
}) })
const publicRouter = new Router({ const publicRouter = new Router({

View file

@ -45,7 +45,7 @@ module.exports = {
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY, INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
MULTI_TENANCY: process.env.MULTI_TENANCY, MULTI_TENANCY: process.env.MULTI_TENANCY,
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS, HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
API_RATE_LIMITING: process.env.API_RATE_LIMITING, API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC,
// environment // environment
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
JEST_WORKER_ID: process.env.JEST_WORKER_ID, JEST_WORKER_ID: process.env.JEST_WORKER_ID,