fix(images): route Next.js Image Optimization to remote backend and eliminate hydration mismatch
This commit is contained in:
1 parent
08ad51152f
commit
379fc1bb77
3 files changed
+73
-33
No files matched your search
@@ -120,17 +120,18 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
<div>
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 bg-canina-blue/5 border border-canina-blue/10 rounded-full mt-3 mb-3 sm:mb-5">
|
||||
<span className="w-2 h-2 rounded-full bg-canina-blue animate-pulse" />
|
||||
<span className="text-canina-blue text-xs font-bold uppercase tracking-widest leading-none">
|
||||
<span suppressHydrationWarning className="text-canina-blue text-xs font-bold uppercase tracking-widest leading-none">
|
||||
{mounted && isInitialized ? getText('hero_badge', "از ۱۹۸۴ در خدمت سلامت حیوانات") : "از ۱۹۸۴ در خدمت سلامت حیوانات"}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<h1 className="text-2xl lg:text-7xl font-black text-medical-gray-900 leading-[1.2] mb-2 sm:mb-6 font-lalezar tracking-wide">
|
||||
<h1 suppressHydrationWarning className="text-2xl lg:text-7xl font-black text-medical-gray-900 leading-[1.2] mb-2 sm:mb-6 font-lalezar tracking-wide">
|
||||
{titleParts[0]} <br />
|
||||
{titleParts[1] && <span className="text-canina-blue ">{titleParts[1]}</span>}
|
||||
</h1>
|
||||
|
||||
<div
|
||||
suppressHydrationWarning
|
||||
className="text-sm lg:text-xl text-medical-gray-600 mb-3 sm:mb-5 max-w-2xl mx-auto lg:mx-0 leading-relaxed font-vazir animate-fade-in [&_p]:text-sm [&_p]:lg:text-xl [&_p]:leading-relaxed [&_p]:my-0 [&_span]:text-inherit"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: subtitle
|
||||
@@ -218,10 +219,10 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
|
||||
{/* Gradient overlay and slide caption */}
|
||||
<div className="absolute bottom-0 left-0 right-0 p-6 sm:p-8 bg-gradient-to-t from-black/85 via-black/40 to-transparent text-white text-right z-20">
|
||||
<div className="text-sm font-medium mb-1 opacity-80 uppercase tracking-widest text-[10px]">
|
||||
<div suppressHydrationWarning className="text-sm font-medium mb-1 opacity-80 uppercase tracking-widest text-[10px]">
|
||||
{mounted && isInitialized ? getText('hero_image_badge', "سرآمد علمی در پزشکی پتها") : "سرآمد علمی در پزشکی پتها"}
|
||||
</div>
|
||||
<div className="text-lg sm:text-xl font-bold italic tracking-tighter">
|
||||
<div suppressHydrationWarning className="text-lg sm:text-xl font-bold italic tracking-tighter">
|
||||
{activeBanner?.title || (mounted && isInitialized ? getText('hero_image_title', "مکملهای تایید شده دامپزشکی با گواهی IFS") : "مکملهای تایید شده دامپزشکی با گواهی IFS")}
|
||||
</div>
|
||||
{activeBanner?.linkUrl && (
|
||||
@@ -283,7 +284,7 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
>
|
||||
<div className="flex flex-col items-center">
|
||||
<span className="text-lg lg:text-xl font-black text-canina-blue leading-none tracking-tighter">DE</span>
|
||||
<span className="text-[6px] lg:text-[7px] font-bold text-medical-gray-500 uppercase tracking-widest mt-0.5 leading-tight">
|
||||
<span suppressHydrationWarning className="text-[6px] lg:text-[7px] font-bold text-medical-gray-500 uppercase tracking-widest mt-0.5 leading-tight">
|
||||
{mounted && isInitialized ? getText('hero_quality_standard', "استاندارد کیفی آلمان") : "استاندارد کیفی آلمان"}
|
||||
</span>
|
||||
</div>
|
||||
@@ -314,7 +315,7 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
</div>
|
||||
<div className="flex flex-col items-center sm:items-start text-center sm:text-right">
|
||||
<div className="text-base sm:text-3xl font-black text-canina-blue font-vazir leading-none">۱۹۸۴</div>
|
||||
<div className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
<div suppressHydrationWarning className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
{mounted && isInitialized ? getText('hero_stat_founded', "سال تاسیس برند") : "سال تاسیس برند"}
|
||||
</div>
|
||||
</div>
|
||||
@@ -329,7 +330,7 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
<div className="flex items-baseline justify-center sm:justify-start">
|
||||
<StatCounter target={40} />
|
||||
</div>
|
||||
<div className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
<div suppressHydrationWarning className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
{mounted && isInitialized ? getText('hero_stat_agencies', "نمایندگی فعال") : "نمایندگی فعال"}
|
||||
</div>
|
||||
</div>
|
||||
@@ -342,7 +343,7 @@ export default function Hero({ banners = [], onShopNavigate }: { banners?: Banne
|
||||
</div>
|
||||
<div className="flex flex-col items-center sm:items-start text-center sm:text-right">
|
||||
<div className="text-base sm:text-3xl font-black text-canina-blue font-vazir leading-none">۱۰۰٪</div>
|
||||
<div className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
<div suppressHydrationWarning className="text-[9px] sm:text-xs text-medical-gray-500 font-extrabold uppercase tracking-tight mt-1 sm:mt-2 font-vazir">
|
||||
{mounted && isInitialized ? getText('hero_stat_german_formula', "فرمول آلمانی") : "فرمول آلمانی"}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -17,33 +17,33 @@ export function getMediaUrl(url?: string | null): string {
|
||||
return trimmed;
|
||||
}
|
||||
|
||||
// If already proxied via /api/uploads/ or /api/media/
|
||||
if (trimmed.startsWith('/api/uploads/') || trimmed.startsWith('/api/media/')) {
|
||||
return trimmed;
|
||||
// Extract the clean upload path
|
||||
let uploadPath = '';
|
||||
if (trimmed.startsWith('/api/uploads/')) {
|
||||
uploadPath = trimmed.replace(/^\/api\/uploads\//, '');
|
||||
} else if (trimmed.startsWith('/api/media/')) {
|
||||
uploadPath = trimmed.replace(/^\/api\/media\//, '');
|
||||
} else if (trimmed.startsWith('/uploads/')) {
|
||||
uploadPath = trimmed.replace(/^\/uploads\//, '');
|
||||
} else if (trimmed.startsWith('uploads/')) {
|
||||
uploadPath = trimmed.replace(/^uploads\//, '');
|
||||
} else if (trimmed.startsWith('/media/')) {
|
||||
uploadPath = trimmed.replace(/^\/media\//, '');
|
||||
} else if (trimmed.startsWith('media/')) {
|
||||
uploadPath = trimmed.replace(/^media\//, '');
|
||||
} else {
|
||||
const uploadsMatch = trimmed.match(/^https?:\/\/[^/]+\/uploads\/(.+)$/i);
|
||||
if (uploadsMatch && uploadsMatch[1]) {
|
||||
uploadPath = uploadsMatch[1];
|
||||
}
|
||||
}
|
||||
|
||||
// If relative path starting with /uploads/
|
||||
if (trimmed.startsWith('/uploads/')) {
|
||||
return `/api/uploads/${trimmed.replace(/^\/uploads\//, '')}`;
|
||||
}
|
||||
|
||||
// If relative path starting with uploads/
|
||||
if (trimmed.startsWith('uploads/')) {
|
||||
return `/api/uploads/${trimmed.replace(/^uploads\//, '')}`;
|
||||
}
|
||||
|
||||
// If relative path starting with /media/ or media/
|
||||
if (trimmed.startsWith('/media/')) {
|
||||
return `/api/uploads/${trimmed.replace(/^\/media\//, '')}`;
|
||||
}
|
||||
if (trimmed.startsWith('media/')) {
|
||||
return `/api/uploads/${trimmed.replace(/^media\//, '')}`;
|
||||
}
|
||||
|
||||
// If full backend URL containing /uploads/ (e.g. http://localhost:4001/uploads/..., https://api.canina.ir/uploads/...)
|
||||
const uploadsMatch = trimmed.match(/^https?:\/\/[^/]+\/uploads\/(.+)$/i);
|
||||
if (uploadsMatch && uploadsMatch[1]) {
|
||||
return `/api/uploads/${uploadsMatch[1]}`;
|
||||
if (uploadPath) {
|
||||
const isStage = typeof window !== 'undefined' && window.location.hostname.includes('stage');
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const backendBase = process.env.NEXT_PUBLIC_API_URL?.replace(/\/api\/?$/, '') ||
|
||||
(isDev ? 'http://localhost:4400' : isStage ? 'https://stageapi.canina.ir' : 'https://api.canina.ir');
|
||||
return `${backendBase}/uploads/${uploadPath}`;
|
||||
}
|
||||
|
||||
// External URLs (like unsplash, cdn, youtube, aparat) stay as-is
|
||||
|
||||
@@ -29,6 +29,11 @@ const nextConfig: NextConfig = {
|
||||
hostname: 'api.canina.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'api.canina.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'stage.canina.ir',
|
||||
@@ -39,11 +44,21 @@ const nextConfig: NextConfig = {
|
||||
hostname: 'stageapi.canina.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'stageapi.canina.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'apicanina.parsaaghayi.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'apicanina.parsaaghayi.ir',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'canina.de',
|
||||
@@ -67,6 +82,30 @@ const nextConfig: NextConfig = {
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'localhost',
|
||||
port: '4400',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'localhost',
|
||||
port: '4001',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: 'localhost',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: '127.0.0.1',
|
||||
port: '4400',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: '127.0.0.1',
|
||||
port: '4001',
|
||||
pathname: '/**',
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user