Spaces:
Sleeping
Sleeping
File size: 1,363 Bytes
2398be6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import { NextRequest, NextResponse } from 'next/server';
const BACKEND_URL = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:5000';
export async function GET(request: NextRequest) {
try {
console.log('π¦ Requesting extension from backend...');
// Forward request to Python backend
const response = await fetch(`${BACKEND_URL}/download-extension`, {
method: 'GET',
});
if (!response.ok) {
throw new Error(`Backend error: ${response.status} ${response.statusText}`);
}
// Get the ZIP file from backend
const buffer = await response.arrayBuffer();
console.log(`β
Extension received from backend (${buffer.byteLength} bytes)`);
// Return the ZIP file
return new NextResponse(buffer, {
status: 200,
headers: {
'Content-Type': 'application/zip',
'Content-Disposition': 'attachment; filename="LinkScout-Extension.zip"',
'Content-Length': buffer.byteLength.toString(),
},
});
} catch (error) {
console.error('β Extension download error:', error);
return NextResponse.json(
{
error: 'Failed to download extension',
message: error instanceof Error ? error.message : 'Unknown error',
hint: 'Please ensure the backend server is running on port 5000'
},
{ status: 500 }
);
}
}
|