This commit is contained in:
Iliyan Angelov
2025-11-25 02:06:38 +02:00
parent 2f6dca736a
commit 82024016cd
37 changed files with 1800 additions and 1478 deletions

View File

@@ -1,4 +1,4 @@
import { API_CONFIG } from '../config/api';
import { API_CONFIG, getApiHeaders } from '../config/api';
// Types for Service API
export interface ServiceFeature {
@@ -104,9 +104,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -134,9 +132,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -164,9 +160,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -194,9 +188,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -224,9 +216,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -254,9 +244,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -284,9 +272,7 @@ export const serviceService = {
const response = await fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
headers: getApiHeaders(),
});
if (!response.ok) {
@@ -442,21 +428,30 @@ export const serviceUtils = {
},
// Get service image URL
// Use relative URLs for same-domain images (Next.js can optimize via rewrites)
// Use absolute URLs only for external images
getServiceImageUrl: (service: Service): string => {
// If service has an uploaded image
if (service.image && typeof service.image === 'string' && service.image.startsWith('/media/')) {
return `${API_CONFIG.BASE_URL}${service.image}`;
// Use relative URL - Next.js rewrite will handle fetching from backend during optimization
return service.image;
}
// If service has an image_url
if (service.image_url) {
if (service.image_url.startsWith('http')) {
// External URL - keep as absolute
return service.image_url;
}
return `${API_CONFIG.BASE_URL}${service.image_url}`;
if (service.image_url.startsWith('/media/')) {
// Same domain media - use relative URL
return service.image_url;
}
// Other relative URLs
return service.image_url;
}
// Fallback to default image
// Fallback to default image (relative is fine for public images)
return '/images/service/default.png';
},