支持为静态资源设置独立地址

This commit is contained in:
CN-JS-HuiBai
2026-04-22 21:23:12 +08:00
parent ba633c8be4
commit ce739d1232
4 changed files with 34 additions and 12 deletions

View File

@@ -151,7 +151,8 @@ function getPublicSiteSettings(settings = {}) {
show_server_ip: settings.show_server_ip ? 1 : 0,
ip_metric_name: settings.ip_metric_name || null,
ip_label_name: settings.ip_label_name || 'address',
custom_metrics: settings.custom_metrics || []
custom_metrics: settings.custom_metrics || [],
cdn_url: settings.cdn_url || null
};
}
@@ -780,6 +781,14 @@ const serveIndex = async (req, res) => {
// Replace <head> with <head> + injection
html = html.replace('<head>', '<head>' + injection);
// Apply CDN URL if set
if (settings.cdn_url) {
const cdnBase = settings.cdn_url.replace(/\/+$/, '');
// Replace relative paths for css, js, fonts, vendor, images
// Matches href="/css/...", src="/js/...", etc.
html = html.replace(/(href|src)="\/+(css|js|fonts|vendor|images|assets)\//g, `$1="${cdnBase}/$2/`);
}
res.send(html);
} catch (err) {
@@ -943,7 +952,8 @@ app.post('/api/settings', requireAuth, async (req, res) => {
const {
page_name, show_page_name, title, logo_url, logo_url_dark, favicon_url,
default_theme, show_95_bandwidth, p95_type, require_login_for_server_details,
icp_filing, ps_filing, show_server_ip, ip_metric_name, ip_label_name, custom_metrics
icp_filing, ps_filing, show_server_ip, ip_metric_name, ip_label_name, custom_metrics,
cdn_url
} = req.body;
// 3. Prepare parameters, prioritizing body but falling back to current
@@ -969,7 +979,8 @@ app.post('/api/settings', requireAuth, async (req, res) => {
show_server_ip: show_server_ip !== undefined ? (show_server_ip ? 1 : 0) : (current.show_server_ip || 0),
ip_metric_name: ip_metric_name !== undefined ? ip_metric_name : (current.ip_metric_name || null),
ip_label_name: ip_label_name !== undefined ? ip_label_name : (current.ip_label_name || 'address'),
custom_metrics: custom_metrics !== undefined ? JSON.stringify(custom_metrics) : (current.custom_metrics || '[]')
custom_metrics: custom_metrics !== undefined ? JSON.stringify(custom_metrics) : (current.custom_metrics || '[]'),
cdn_url: cdn_url !== undefined ? cdn_url : (current.cdn_url || null)
};
await db.query(`
@@ -978,8 +989,8 @@ app.post('/api/settings', requireAuth, async (req, res) => {
default_theme, show_95_bandwidth, p95_type, require_login_for_server_details,
blackbox_source_id, latency_source, latency_dest, latency_target,
icp_filing, ps_filing, show_server_ip, ip_metric_name, ip_label_name,
custom_metrics
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
custom_metrics, cdn_url
) VALUES (1, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
page_name = VALUES(page_name),
show_page_name = VALUES(show_page_name),
@@ -1000,13 +1011,15 @@ app.post('/api/settings', requireAuth, async (req, res) => {
show_server_ip = VALUES(show_server_ip),
ip_metric_name = VALUES(ip_metric_name),
ip_label_name = VALUES(ip_label_name),
custom_metrics = VALUES(custom_metrics)`,
custom_metrics = VALUES(custom_metrics),
cdn_url = VALUES(cdn_url)`,
[
settings.page_name, settings.show_page_name, settings.title, settings.logo_url, settings.logo_url_dark, settings.favicon_url,
settings.default_theme, settings.show_95_bandwidth, settings.p95_type, settings.require_login_for_server_details,
settings.blackbox_source_id, settings.latency_source, settings.latency_dest, settings.latency_target,
settings.icp_filing, settings.ps_filing, settings.show_server_ip,
settings.ip_metric_name, settings.ip_label_name, settings.custom_metrics
settings.ip_metric_name, settings.ip_label_name, settings.custom_metrics,
settings.cdn_url
]
);