-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: proxy frame image requests (#1049)
- Loading branch information
1 parent
a16234e
commit dab3447
Showing
3 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export async function GET(request: NextRequest) { | ||
const { searchParams } = new URL(request.url); | ||
const url = searchParams.get('url'); | ||
|
||
if (!url) { | ||
return NextResponse.json({ error: 'Missing url' }, { status: 400 }); | ||
} | ||
|
||
try { | ||
const response = await fetch(url); | ||
if (!response.ok) { | ||
throw new Error(`Failed to fetch image: ${response.statusText}`); | ||
} | ||
const contentType = response.headers.get('content-type'); | ||
const imageBuffer = await response.arrayBuffer(); | ||
return new NextResponse(imageBuffer, { | ||
status: 200, | ||
headers: { | ||
'Content-Type': contentType ?? 'application/octet-stream', | ||
'Cache-Control': 'public, max-age=86400', | ||
}, | ||
}); | ||
} catch (error) { | ||
console.error('Error fetching image:', error); | ||
return NextResponse.json({ error: 'Failed to fetch image' }, { status: 500 }); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters