import { defineEventHandler } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../utils/tenant' import { getAppProductById } from '../../utils/app' import type { TenantContext } from '~/app/types' /** * 获取当前应用信息 * GET /api/app/info * * 优先返回中间件已识别的 AppProduct(event.context.tenant.appProduct) * 若中间件未查到(异常降级),则用 appId 实时补查 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const tenant = event.context?.tenant as TenantContext | undefined // 中间件已查到直接返回 if (tenant?.appProduct) { return tenant.appProduct } // 兜底:实时查询 const appProduct = await getAppProductById(ctx.appId, config) return appProduct || null })