fix: update image URL handling to support paths without leading slashes and clean up layout file

This commit is contained in:
Wini_Fy
2026-02-05 10:52:30 +07:00
parent 0bad73da4c
commit 879d71f7ab
2 changed files with 11 additions and 3 deletions

View File

@@ -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("/")) {