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 = () => {