22 lines
636 B
TypeScript
22 lines
636 B
TypeScript
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',
|
||
})
|
||
}
|
||
}
|