Files
order_site/apps/backend/src/services/dev-mock/dev-mock-enabled.ts
T

22 lines
636 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { isProductionLike } from '../../config/runtime-validation.js'
import { createHttpError } from '../../utils/http.js'
export function isDevMockEnabled(env: NodeJS.ProcessEnv = process.env): boolean {
const flag = String(env.ENABLE_DEV_MOCK || '')
.trim()
.toLowerCase()
if (flag === '1' || flag === 'true') {
return true
}
return !isProductionLike(env)
}
export function assertDevMockEnabled() {
if (!isDevMockEnabled()) {
throw createHttpError('当前环境未开启开发 Mock(仅非 production 或 ENABLE_DEV_MOCK=1)', {
statusCode: 403,
errorCode: 'dev_mock_disabled',
})
}
}