update at 2026-02-09 16:09:44

This commit is contained in:
douboer
2026-02-09 16:09:44 +08:00
parent ffb7367d3a
commit 917f210dae
20 changed files with 790 additions and 184 deletions

View File

@@ -0,0 +1,54 @@
// 远端服务配置(统一修改入口)
// 更换服务器时,仅需修改这里。
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,
}