Reubencf's picture
Qr code working
5de7420
raw
history blame
1.14 kB
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 }
);
}
// Fetch the image
const response = await axios.get(imageUrl, {
responseType: 'arraybuffer',
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
});
// Get content type from response
const contentType = response.headers['content-type'] || 'image/png';
// Return the image with proper headers
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 }
);
}
}