1
0
Fork 0
mirror of synced 2024-06-20 19:30:28 +12:00
budibase/packages/server/src/middleware/appInfo.ts

21 lines
607 B
TypeScript

import { isDevAppID, isProdAppID } from "../db/utils"
import { BBContext } from "@budibase/types"
export enum AppType {
DEV = "dev",
PROD = "prod",
}
export function middleware({ appType }: { appType?: AppType } = {}) {
return (ctx: BBContext, next: any) => {
const appId = ctx.appId
if (appType === AppType.DEV && appId && !isDevAppID(appId)) {
ctx.throw(400, "Only apps in development support this endpoint")
}
if (appType === AppType.PROD && appId && !isProdAppID(appId)) {
ctx.throw(400, "Only apps in production support this endpoint")
}
return next()
}
}