feat: add instagram image proxy to bypass client DNS blocks
This commit is contained in:
+1
-1
@@ -22,7 +22,7 @@ async function getInstagramData() {
|
||||
username: 'moy_akyaka',
|
||||
maxId: ''
|
||||
}),
|
||||
next: { revalidate: 86400 } // 24 hours
|
||||
next: { revalidate: 3600 } // 1 hour to prevent CDN link expiration
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const url = request.nextUrl.searchParams.get('url');
|
||||
|
||||
if (!url) {
|
||||
return new NextResponse('Missing url parameter', { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
headers: {
|
||||
// Use a generic user agent
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
|
||||
}
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('Failed to proxy instagram image:', res.status, res.statusText);
|
||||
return new NextResponse('Failed to fetch image', { status: res.status });
|
||||
}
|
||||
|
||||
const buffer = await res.arrayBuffer();
|
||||
|
||||
const headers = new Headers();
|
||||
headers.set('Content-Type', res.headers.get('Content-Type') || 'image/jpeg');
|
||||
headers.set('Cache-Control', 'public, max-age=86400, s-maxage=86400');
|
||||
|
||||
return new NextResponse(buffer, { headers });
|
||||
} catch (error) {
|
||||
console.error('Error in instagram proxy:', error);
|
||||
return new NextResponse('Error fetching image', { status: 500 });
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ export default function InstagramFeed({ dict, posts = [] }: { dict: any, posts?:
|
||||
|
||||
<div className="relative aspect-[4/5] w-full overflow-hidden bg-sand-dark/10">
|
||||
<img
|
||||
src={post.imageUrl || ''}
|
||||
src={post.imageUrl ? `/api/instagram-proxy?url=${encodeURIComponent(post.imageUrl)}` : ''}
|
||||
alt={post.caption ? post.caption.substring(0, 50) : 'Instagram Post'}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-700"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user