diff --git a/app/layout.tsx b/app/layout.tsx index c1bbf86..5027846 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("/")) {