fix(media): fix broken image URLs after deploy - add API domains to next.config and resolve relative /uploads/ paths with backend base URL
This commit is contained in:
parent
33f15f7b5b
commit
873376be26
@ -121,11 +121,14 @@ export class ProductService {
|
||||
optimisticTemplate: data.optimisticTemplate,
|
||||
feedingAdvice: data.dosageLogic || data.feedingAdvice || '',
|
||||
slug: data.slug,
|
||||
image: (data.imageUrl && (data.imageUrl.startsWith('http://') || data.imageUrl.startsWith('https://')))
|
||||
? data.imageUrl
|
||||
: (data.imageUrl && data.imageUrl.startsWith('/uploads/')
|
||||
? data.imageUrl
|
||||
: (local?.image || (data.imageUrl && !data.imageUrl.startsWith('/products/') ? data.imageUrl : '') || '/assets/images/hero-section-image.png')),
|
||||
image: (() => {
|
||||
const apiBase = (process.env.NEXT_PUBLIC_API_URL || '').replace(/\/api$/, '');
|
||||
if (!data.imageUrl) return local?.image || '/assets/images/hero-section-image.png';
|
||||
if (data.imageUrl.startsWith('http://') || data.imageUrl.startsWith('https://')) return data.imageUrl;
|
||||
if (data.imageUrl.startsWith('/uploads/')) return `${apiBase}${data.imageUrl}`;
|
||||
if (data.imageUrl.startsWith('/products/')) return local?.image || '/assets/images/hero-section-image.png';
|
||||
return local?.image || data.imageUrl || '/assets/images/hero-section-image.png';
|
||||
})(),
|
||||
|
||||
main_ingredients: data.ingredientList?.map(i => i.ingredient) || data.ingredients?.split(/[،,-]/).map(s => s.trim()).filter(Boolean) || [],
|
||||
symptoms: data.symptoms?.map(s => typeof s === 'string' ? s : s.symptom || '').filter(Boolean) || [],
|
||||
|
||||
@ -13,6 +13,22 @@ const nextConfig: NextConfig = {
|
||||
images: {
|
||||
formats: ['image/avif', 'image/webp'],
|
||||
remotePatterns: [
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'canina.ir',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'api.canina.ir',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'stage.canina.ir',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'stageapi.canina.ir',
|
||||
},
|
||||
{
|
||||
protocol: 'https',
|
||||
hostname: 'canina-iran.com',
|
||||
@ -29,6 +45,10 @@ const nextConfig: NextConfig = {
|
||||
protocol: 'http',
|
||||
hostname: 'localhost',
|
||||
},
|
||||
{
|
||||
protocol: 'http',
|
||||
hostname: '127.0.0.1',
|
||||
},
|
||||
],
|
||||
},
|
||||
async headers() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user