From 78e69152b4488335cb7264e769e9ed01d7a6d762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=88=BD=E5=93=92=E5=93=92?= Date: Sat, 21 Mar 2026 11:39:24 +0800 Subject: [PATCH] fix: extract pathname from absolute image URLs to avoid container host leaking --- frontend/src/components/competition/ProjectDetail.jsx | 8 ++++---- frontend/src/pages/Home.jsx | 6 ++++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/competition/ProjectDetail.jsx b/frontend/src/components/competition/ProjectDetail.jsx index 3eaf105..0f955e0 100644 --- a/frontend/src/components/competition/ProjectDetail.jsx +++ b/frontend/src/components/competition/ProjectDetail.jsx @@ -17,10 +17,10 @@ const { useBreakpoint } = Grid; const getImageUrl = (url) => { if (!url) return ''; - if (url.startsWith('http') || url.startsWith('//')) return url; - const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8000/api'; - const baseUrl = apiUrl.replace(/\/api\/?$/, ''); - return `${baseUrl}${url}`; + if (url.startsWith('http') || url.startsWith('//')) { + try { return new URL(url).pathname; } catch { return url; } + } + return url; }; const CodeBlock = ({ inline, className, children, ...props }) => { diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 9e08452..2db6fc1 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -11,8 +11,10 @@ const { Title, Paragraph } = Typography; // 获取完整图片 URL const getImageUrl = (url) => { if (!url) return ''; - if (url.startsWith('http') || url.startsWith('//')) return url; - return `http://localhost:8876${url}`; + if (url.startsWith('http') || url.startsWith('//')) { + try { return new URL(url).pathname; } catch { return url; } + } + return url; }; const Home = () => {