|
|
import { NextResponse } from 'next/server'; |
|
|
import axios from 'axios'; |
|
|
|
|
|
export async function GET(request) { |
|
|
try { |
|
|
const { searchParams } = new URL(request.url); |
|
|
const imageUrl = searchParams.get('url'); |
|
|
|
|
|
if (!imageUrl) { |
|
|
return NextResponse.json( |
|
|
{ error: 'Image URL is required' }, |
|
|
{ status: 400 } |
|
|
); |
|
|
} |
|
|
|
|
|
|
|
|
const response = await axios.get(imageUrl, { |
|
|
responseType: 'arraybuffer', |
|
|
headers: { |
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36' |
|
|
} |
|
|
}); |
|
|
|
|
|
|
|
|
const contentType = response.headers['content-type'] || 'image/png'; |
|
|
|
|
|
|
|
|
return new NextResponse(response.data, { |
|
|
status: 200, |
|
|
headers: { |
|
|
'Content-Type': contentType, |
|
|
'Cache-Control': 'public, max-age=3600', |
|
|
'Access-Control-Allow-Origin': '*' |
|
|
} |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
console.error('Error proxying image:', error); |
|
|
return NextResponse.json( |
|
|
{ error: 'Failed to fetch image' }, |
|
|
{ status: 500 } |
|
|
); |
|
|
} |
|
|
} |