Fix for url previews

This commit is contained in:
Christopher
2026-01-22 13:25:15 -08:00
parent 67a97ea8c4
commit fc86bc1901
2 changed files with 14 additions and 8 deletions
+13 -7
View File
@@ -14,15 +14,21 @@ export async function GET(req: NextRequest) {
url = 'https://' + url;
}
const response = await fetch(url, {
headers: {
'User-Agent': 'SynapsisBot/1.0',
},
signal: AbortSignal.timeout(5000), // 5s timeout
});
let response;
try {
response = await fetch(url, {
headers: {
'User-Agent': 'SynapsisBot/1.0',
},
signal: AbortSignal.timeout(5000), // 5s timeout
});
} catch (fetchError) {
console.warn(`Fetch failed for URL: ${url}`, fetchError);
return NextResponse.json({ error: 'Could not reach the URL' }, { status: 404 });
}
if (!response.ok) {
throw new Error(`Failed to fetch URL: ${response.status}`);
return NextResponse.json({ error: `URL returned status ${response.status}` }, { status: 404 });
}
const html = await response.text();