perf: stream Stripstream images and increase image fetch timeout
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:
2026-03-14 17:53:37 +01:00
parent 100d8b37e7
commit fc9c220be6
2 changed files with 10 additions and 8 deletions

View File

@@ -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");

View File

@@ -3,6 +3,7 @@ import { ERROR_CODES } from "@/constants/errorCodes";
import logger from "@/lib/logger";
const TIMEOUT_MS = 15000;
const IMAGE_TIMEOUT_MS = 60000;
interface FetchErrorLike { code?: string; cause?: { code?: string } }
@@ -149,7 +150,7 @@ export class StripstreamClient {
Accept: "image/webp, image/jpeg, image/png, */*",
});
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), TIMEOUT_MS);
const timeoutId = setTimeout(() => controller.abort(), IMAGE_TIMEOUT_MS);
try {
const response = await fetch(url, { headers, signal: controller.signal });
if (!response.ok) {