Files
font2pic/miniprogram/config/server.js
2026-02-09 16:09:44 +08:00

55 lines
1.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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