PR comments and fixes.

This commit is contained in:
mike12345567 2024-12-05 11:36:56 +00:00
parent 83448febf4
commit 48379021ef
7 changed files with 25 additions and 14 deletions

View File

@ -1,6 +1,10 @@
import { Ctx } from "@budibase/types"
import { Middleware, Next } from "koa"
export default async (ctx: Ctx, next: any) => {
// this middleware exists purely to be overridden by middlewares supplied by the @budibase/pro library
const middleware = (async (ctx: Ctx, next: Next) => {
// Placeholder for audit log middleware
return next()
}
}) as Middleware
export default middleware

View File

@ -8,6 +8,7 @@ import {
GetTenantIdOptions,
TenantResolutionStrategy,
} from "@budibase/types"
import { Next, Middleware } from "koa"
export default function (
allowQueryStringPatterns: EndpointMatcher[],
@ -17,7 +18,7 @@ export default function (
const allowQsOptions = buildMatcherRegex(allowQueryStringPatterns)
const noTenancyOptions = buildMatcherRegex(noTenancyPatterns)
return async function (ctx: Ctx, next: any) {
return async function (ctx: Ctx, next: Next) {
const allowNoTenant =
opts.noTenancyRequired || !!matches(ctx, noTenancyOptions)
const tenantOpts: GetTenantIdOptions = {
@ -32,5 +33,5 @@ export default function (
const tenantId = getTenantIDFromCtx(ctx, tenantOpts)
ctx.set(Header.TENANT_ID, tenantId as string)
return doInTenant(tenantId, next)
}
} as Middleware
}

View File

@ -58,12 +58,9 @@ if (apiEnabled()) {
})
)
.use(pro.licensing())
// @ts-ignore
.use(currentApp)
.use(auth.auditLog)
// @ts-ignore
.use(migrations)
// @ts-ignore
.use(cleanup)
// authenticated routes

View File

@ -1,8 +1,9 @@
import { UserCtx } from "@budibase/types"
import { checkMissingMigrations } from "../appMigrations"
import env from "../environment"
import { Middleware, Next } from "koa"
export default async (ctx: UserCtx, next: any) => {
const middleware = (async (ctx: UserCtx, next: Next) => {
const { appId } = ctx
// migrations can be disabled via environment variable if you
@ -16,4 +17,6 @@ export default async (ctx: UserCtx, next: any) => {
}
return checkMissingMigrations(ctx, next, appId)
}
}) as Middleware
export default middleware

View File

@ -1,8 +1,9 @@
import { Ctx } from "@budibase/types"
import { context } from "@budibase/backend-core"
import { tracer } from "dd-trace"
import { Middleware, Next } from "koa"
export default async (ctx: Ctx, next: any) => {
const middleware = (async (ctx: Ctx, next: Next) => {
const resp = await next()
const current = context.getCurrentContext()
@ -30,4 +31,6 @@ export default async (ctx: Ctx, next: any) => {
}
return resp
}
}) as Middleware
export default middleware

View File

@ -13,8 +13,9 @@ import env from "../environment"
import { isWebhookEndpoint, isBrowser, isApiKey } from "./utils"
import { UserCtx, ContextUser } from "@budibase/types"
import tracer from "dd-trace"
import { Middleware, Next } from "koa"
export default async (ctx: UserCtx, next: any) => {
const middleware = (async (ctx: UserCtx, next: Next) => {
// try to get the appID from the request
let requestAppId = await utils.getAppIdFromCtx(ctx)
if (!requestAppId) {
@ -116,4 +117,6 @@ export default async (ctx: UserCtx, next: any) => {
return next()
})
}
}) as Middleware
export default middleware

View File

@ -47,7 +47,7 @@ export interface BBRequest<RequestBody> extends Request {
export interface Ctx<RequestBody = any, ResponseBody = any> extends Context {
request: BBRequest<RequestBody>
body: ResponseBody
userAgent: UserAgentContext["userAgent"]
userAgent?: UserAgentContext["userAgent"]
state: { nonce?: string }
}