// 远端服务配置(统一修改入口) // 更换服务器时,仅需修改这里。 const SERVER_CONFIG = { protocol: 'https', host: 'fonts.biboer.cn', // 留空表示使用协议默认端口(https:443 / http:80) port: '', apiPrefix: '/api', fontsManifestPath: '/miniprogram/assets/fonts.json', defaultConfigPath: '/miniprogram/assets/default.json', } function buildOrigin() { const protocol = String(SERVER_CONFIG.protocol || 'https').replace(/:$/, '') const host = String(SERVER_CONFIG.host || '').trim() const port = String(SERVER_CONFIG.port || '').trim() if (!host) { throw new Error('SERVER_CONFIG.host 未配置') } const hasDefaultPort = (protocol === 'https' && port === '443') || (protocol === 'http' && port === '80') const portPart = !port || hasDefaultPort ? '' : `:${port}` return `${protocol}://${host}${portPart}` } function normalizePath(path, fallback) { const value = String(path || fallback || '').trim() if (!value) { return '/' } return value.startsWith('/') ? value : `/${value}` } function buildRuntimeConfig() { const origin = buildOrigin() const apiPrefix = normalizePath(SERVER_CONFIG.apiPrefix, '/api').replace(/\/$/, '') const fontsManifestPath = normalizePath(SERVER_CONFIG.fontsManifestPath, '/miniprogram/assets/fonts.json') const defaultConfigPath = normalizePath(SERVER_CONFIG.defaultConfigPath, '/miniprogram/assets/default.json') return { fontsBaseUrl: origin, fontsManifestUrl: `${origin}${fontsManifestPath}`, defaultConfigUrl: `${origin}${defaultConfigPath}`, svgRenderApiUrl: `${origin}${apiPrefix}/render-svg`, pngRenderApiUrl: `${origin}${apiPrefix}/render-png`, } } module.exports = { SERVER_CONFIG, buildRuntimeConfig, }