diff --git a/src/services/blogService.ts b/src/services/blogService.ts index 6abc274..8ec06bc 100644 --- a/src/services/blogService.ts +++ b/src/services/blogService.ts @@ -72,6 +72,7 @@ class BlogService { throw new Error(`HTTP error! status: ${response.status}`); } const apiBlogs: ApiBlog[] = await response.json(); + console.log('Raw API response:', JSON.stringify(apiBlogs, null, 2)); return this.transformApiBlogsToBlogs(apiBlogs); } catch (error) { console.error('Error fetching posted blogs:', error); @@ -166,17 +167,23 @@ class BlogService { } private getImageUrl(imageUrl?: string): string { + // Debug logging + console.log('Processing imageUrl:', imageUrl); + // Return default if no imageUrl provided if (!imageUrl || imageUrl.trim() === '') { + console.log('No imageUrl provided, using default'); return this.getDefaultImage(); } try { // Decode if the URL is encoded const decodedUrl = imageUrl.includes('%') ? decodeURIComponent(imageUrl) : imageUrl; + console.log('Decoded URL:', decodedUrl); // If it's already a complete URL, return as is if (decodedUrl.startsWith('http://') || decodedUrl.startsWith('https://')) { + console.log('Complete URL, returning as is'); return decodedUrl; } @@ -184,14 +191,19 @@ class BlogService { if (decodedUrl.startsWith('/')) { // Check if it's a local public path if (decodedUrl.startsWith('/images/')) { + console.log('Local public image'); return decodedUrl; } // It's from the backend API - return `${this.apiBaseUrl}${decodedUrl}`; + const fullUrl = `${this.apiBaseUrl}${decodedUrl}`; + console.log('Backend relative path, constructing:', fullUrl); + return fullUrl; } // Otherwise, assume it's a backend path without leading / - return `${this.apiBaseUrl}/${decodedUrl}`; + const fullUrl = `${this.apiBaseUrl}/${decodedUrl}`; + console.log('Backend path without leading /, constructing:', fullUrl); + return fullUrl; } catch (error) { console.error('Error processing image URL:', imageUrl, error); return this.getDefaultImage(); @@ -199,7 +211,8 @@ class BlogService { } private getDefaultImage(): string { - return '/images/default-blog-image.jpg'; + // Use a placeholder image service for now + return 'https://images.unsplash.com/photo-1505751172876-fa1923c5c528?w=800&h=600&fit=crop'; } private getFallbackBlogs(): Blog[] {