function safeRequire(modulePath) { try { return require(modulePath) } catch (error) { return {} } } function getEnvVersion() { if (typeof wx === 'undefined') { return 'develop' } try { if (typeof wx.getAccountInfoSync === 'function') { const accountInfo = wx.getAccountInfoSync() const miniProgram = accountInfo && accountInfo.miniProgram if (miniProgram && miniProgram.envVersion) { return miniProgram.envVersion } } } catch (error) {} return 'develop' } function getRuntimePlatform() { if (typeof wx === 'undefined') { return 'devtools' } try { const systemInfo = wx.getSystemInfoSync() if (systemInfo && systemInfo.platform) { return systemInfo.platform } } catch (error) {} return 'unknown' } function normalizeDomain(value, fallbackValue) { const target = String(value || fallbackValue || '').trim() return target.replace(/\/+$/, '') } function ensureHttps(value, envVersion) { if (!value) { throw new Error(`Missing API domain for ${envVersion}`) } if (envVersion !== 'develop' && !value.startsWith('https://')) { throw new Error(`${envVersion} environment must use HTTPS`) } return value } const localOverride = safeRequire('./config.local') const ENV_VERSION = getEnvVersion() const RUNTIME_PLATFORM = getRuntimePlatform() const IS_DEVTOOLS = RUNTIME_PLATFORM === 'devtools' const DEFAULT_DOMAINS = { local: 'http://127.0.0.1:80', tunnel: 'https://yunail.art', 'dev-remote': 'https://yunail.art', trial: 'https://yunail.art', release: 'https://yunail.art' } const DOMAIN_MAP = { ...DEFAULT_DOMAINS, ...(localOverride.domains || {}) } const DEFAULT_DEVELOP_TARGET = IS_DEVTOOLS ? 'local' : 'dev-remote' const DEVELOP_TARGET = String(localOverride.developTarget || DEFAULT_DEVELOP_TARGET) const API_DOMAIN = ensureHttps( ENV_VERSION === 'develop' ? normalizeDomain(DOMAIN_MAP[DEVELOP_TARGET], DOMAIN_MAP['dev-remote']) : normalizeDomain(DOMAIN_MAP[ENV_VERSION], DOMAIN_MAP.release), ENV_VERSION ) module.exports = { ENV_VERSION, RUNTIME_PLATFORM, IS_DEVTOOLS, DEVELOP_TARGET, API_DOMAIN, ADMIN_API_BASE_URL: `${API_DOMAIN}/admin/api`, IS_DEV_ENV: ENV_VERSION === 'develop', REQUEST_TIMEOUT: Number(localOverride.requestTimeout || 10000), ENABLE_REQUEST_SIGNING: localOverride.enableRequestSigning !== false, IDLE_TIMEOUT_MS: 30 * 60 * 1000, IDLE_WARNING_MS: 2 * 60 * 1000, CACHE_TTL: { permissions: 2 * 60 * 1000, dict: 5 * 60 * 1000, workbench: 60 * 1000 }, TAB_PAGES: [ '/pages/workbench/index', '/pages/orders/index', '/pages/manage/index', '/pages/profile/index' ] }