mirror of https://github.com/kortix-ai/suna.git
Merge pull request #419 from rishimohan/main
fix: generate share page og image on edge
This commit is contained in:
commit
f9e9c05db1
|
@ -1,9 +1,19 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
|
||||
// Add route segment config for caching
|
||||
export const runtime = 'edge'; // Use edge runtime for better performance
|
||||
export const revalidate = 3600; // Cache for 1 hour
|
||||
|
||||
export async function GET(request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const title = searchParams.get('title');
|
||||
|
||||
// Add error handling
|
||||
if (!title) {
|
||||
return new NextResponse('Missing title parameter', { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`https://api.orshot.com/v1/studio/render`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
@ -21,6 +31,10 @@ export async function GET(request) {
|
|||
}),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Orshot API error: ${response.status}`);
|
||||
}
|
||||
|
||||
const blob = await response.blob();
|
||||
const arrayBuffer = await blob.arrayBuffer();
|
||||
const image = Buffer.from(arrayBuffer);
|
||||
|
@ -29,6 +43,11 @@ export async function GET(request) {
|
|||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'image/png',
|
||||
'Cache-Control': 'public, max-age=3600, stale-while-revalidate=86400',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('OG Image generation error:', error);
|
||||
return new NextResponse('Error generating image', { status: 500 });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue