From 879d71f7ab7d89d0abc5657c3003e00f243a52c2 Mon Sep 17 00:00:00 2001 From: Wini_Fy Date: Thu, 5 Feb 2026 10:52:30 +0700 Subject: [PATCH] fix: update image URL handling to support paths without leading slashes and clean up layout file --- app/layout.tsx | 1 - utils/image.ts | 13 +++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index 7e73f2b..3e8c2d3 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -22,7 +22,6 @@ export default function RootLayout({ - diff --git a/utils/image.ts b/utils/image.ts index cf7dcdc..fa4eae6 100644 --- a/utils/image.ts +++ b/utils/image.ts @@ -14,9 +14,18 @@ export function getCmsImageUrl(imagePath: string | undefined): string { return imagePath; } - if (imagePath.startsWith("/uploads/") || imagePath.startsWith("/img/")) { + // Hỗ trợ cả "/uploads/", "uploads/", "/img/", "img/" + if ( + imagePath.startsWith("/uploads/") || + imagePath.startsWith("uploads/") || + imagePath.startsWith("/img/") || + imagePath.startsWith("img/") + ) { const apiUrl = process.env.NEXT_PUBLIC_API_URL || "http://localhost:3001"; - return `${apiUrl}${imagePath}`; + // Nếu thiếu dấu "/" đầu, thêm vào cho đúng path + const fixedPath = + imagePath.startsWith("/") ? imagePath : `/${imagePath}`; + return `${apiUrl}${fixedPath}`; } if (imagePath.startsWith("/")) {