diff --git a/packages/backend-core/src/middleware/auditLog.ts b/packages/backend-core/src/middleware/auditLog.ts index 2febbf879c..f4cbb8b45f 100644 --- a/packages/backend-core/src/middleware/auditLog.ts +++ b/packages/backend-core/src/middleware/auditLog.ts @@ -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 diff --git a/packages/backend-core/src/middleware/tenancy.ts b/packages/backend-core/src/middleware/tenancy.ts index e0c1be2a03..a614ab5438 100644 --- a/packages/backend-core/src/middleware/tenancy.ts +++ b/packages/backend-core/src/middleware/tenancy.ts @@ -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 } diff --git a/packages/server/src/api/index.ts b/packages/server/src/api/index.ts index 92cee95ea6..230e5079b4 100644 --- a/packages/server/src/api/index.ts +++ b/packages/server/src/api/index.ts @@ -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 diff --git a/packages/server/src/middleware/appMigrations.ts b/packages/server/src/middleware/appMigrations.ts index 6ad356427b..c8fcfa217e 100644 --- a/packages/server/src/middleware/appMigrations.ts +++ b/packages/server/src/middleware/appMigrations.ts @@ -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 diff --git a/packages/server/src/middleware/cleanup.ts b/packages/server/src/middleware/cleanup.ts index fa04743cee..7279c4cddc 100644 --- a/packages/server/src/middleware/cleanup.ts +++ b/packages/server/src/middleware/cleanup.ts @@ -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 diff --git a/packages/server/src/middleware/currentapp.ts b/packages/server/src/middleware/currentapp.ts index 6b44e56a66..796098a4d2 100644 --- a/packages/server/src/middleware/currentapp.ts +++ b/packages/server/src/middleware/currentapp.ts @@ -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 diff --git a/packages/types/src/sdk/koa.ts b/packages/types/src/sdk/koa.ts index 826b7b371c..deb457d009 100644 --- a/packages/types/src/sdk/koa.ts +++ b/packages/types/src/sdk/koa.ts @@ -47,7 +47,7 @@ export interface BBRequest extends Request { export interface Ctx extends Context { request: BBRequest body: ResponseBody - userAgent: UserAgentContext["userAgent"] + userAgent?: UserAgentContext["userAgent"] state: { nonce?: string } }