perf: stream Stripstream images and increase image fetch timeout
Some checks failed
Build, Push & Deploy / deploy (push) Failing after 3s
Some checks failed
Build, Push & Deploy / deploy (push) Failing after 3s
Stream image responses directly to the client instead of buffering the entire image in memory, reducing perceived latency. Increase image fetch timeout from 15s to 60s to avoid AbortError on slow page loads. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -35,14 +35,15 @@ export async function GET(
|
||||
const response = await client.fetchImage(path);
|
||||
|
||||
const contentType = response.headers.get("content-type") ?? "image/jpeg";
|
||||
const buffer = await response.arrayBuffer();
|
||||
const contentLength = response.headers.get("content-length");
|
||||
|
||||
return new NextResponse(buffer, {
|
||||
headers: {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
},
|
||||
});
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": contentType,
|
||||
"Cache-Control": "public, max-age=86400",
|
||||
};
|
||||
if (contentLength) headers["Content-Length"] = contentLength;
|
||||
|
||||
return new NextResponse(response.body, { headers });
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, "Stripstream page fetch error");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user