const isDev = require('electron-is-dev') const fs = require('fs') const path = require('path') const { app } = require('electron') const urlENV = { development: { WEB_BASE: 'http://192.168.17.26:9999', // WEB_BASE: 'http://med-pigx-client:9999', // WEB_BASE: 'https://test-manage.hengfangjiankang.com/service', // WEB_BASE: 'https://manage.hengfangjiankang.com/api', HOOK_BASE: 'http://127.0.0.1:6666/', LOCAL_BASE: 'http://127.0.0.1:7777/', OSS_BASE: 'https://oss.hengfangjiankang.com/', WEL_TIME: '0 30 19 * * *' // 定时群欢迎,19:30 }, test: { WEB_BASE: 'https://test-manage.hengfangjiankang.com/service', LOCAL_BASE: 'http://127.0.0.1:7777/', HOOK_BASE: 'http://127.0.0.1:6666/', OSS_BASE: 'https://oss.hengfangjiankang.com/', WEL_TIME: '0 30 16 * * *' // 定时群欢迎,18:00 }, production: { WEB_BASE: 'https://manage.hengfangjiankang.com/api', // WEB_BASE: 'https://5115x374k6.wocp.fun', // WEB_BASE: 'http://192.168.90.11:9999', // sag // WEB_BASE: 'http://192.168.0.31:9999', // 内网 王媛 // WEB_BASE: 'http://med-pigx-client:9999', LOCAL_BASE: 'http://127.0.0.1:7777/', HOOK_BASE: 'http://127.0.0.1:6666/', OSS_BASE: 'https://oss.hengfangjiankang.com/', WEL_TIME: '0 30 19 * * *' // 定时群欢迎,19:30 }, } type Env = keyof typeof urlENV type UrlENV = (typeof urlENV)[Env] type RuntimeConfigKey = keyof UrlENV const runtimeConfigKeys: RuntimeConfigKey[] = [ 'WEB_BASE', 'LOCAL_BASE', 'HOOK_BASE', 'OSS_BASE', 'WEL_TIME' ] function isEnv(value: string): value is Env { return value in urlENV } function getRuntimeConfigPath(): string { if (app?.isPackaged) { return path.join(process.resourcesPath, 'unpacked', 'runtime-config.json') } return path.resolve('runtime-config.json') } function readRuntimeConfig(env: Env): Partial { if (env === 'production') { return {} } const runtimeConfigPath = getRuntimeConfigPath() if (!fs.existsSync(runtimeConfigPath)) { return {} } try { const runtimeConfig = JSON.parse(fs.readFileSync(runtimeConfigPath, 'utf-8')) return runtimeConfigKeys.reduce>((config, key) => { const value = runtimeConfig?.[key] if (typeof value === 'string' && value.trim()) { config[key] = value.trim() } return config }, {}) } catch (error) { console.log('runtime-config.json 读取失败,已使用内置配置', error) return {} } } const buildMode = import.meta.env.MODE const env: Env = isEnv(buildMode) ? buildMode : isDev ? 'development' : 'production' const runtimeConfig = readRuntimeConfig(env) export default { env: env, urlENV: { ...urlENV[env], ...runtimeConfig } }