fix: extract pathname from absolute image URLs to avoid container host leaking
All checks were successful
Deploy to Server / deploy (push) Successful in 1m54s

This commit is contained in:
爽哒哒
2026-03-21 11:39:24 +08:00
parent 0ecf0d8f7d
commit 78e69152b4
2 changed files with 8 additions and 6 deletions

View File

@@ -17,10 +17,10 @@ const { useBreakpoint } = Grid;
const getImageUrl = (url) => { const getImageUrl = (url) => {
if (!url) return ''; if (!url) return '';
if (url.startsWith('http') || url.startsWith('//')) return url; if (url.startsWith('http') || url.startsWith('//')) {
const apiUrl = import.meta.env.VITE_API_URL || 'http://localhost:8000/api'; try { return new URL(url).pathname; } catch { return url; }
const baseUrl = apiUrl.replace(/\/api\/?$/, ''); }
return `${baseUrl}${url}`; return url;
}; };
const CodeBlock = ({ inline, className, children, ...props }) => { const CodeBlock = ({ inline, className, children, ...props }) => {

View File

@@ -11,8 +11,10 @@ const { Title, Paragraph } = Typography;
// 获取完整图片 URL // 获取完整图片 URL
const getImageUrl = (url) => { const getImageUrl = (url) => {
if (!url) return ''; if (!url) return '';
if (url.startsWith('http') || url.startsWith('//')) return url; if (url.startsWith('http') || url.startsWith('//')) {
return `http://localhost:8876${url}`; try { return new URL(url).pathname; } catch { return url; }
}
return url;
}; };
const Home = () => { const Home = () => {