_next/image endpoint does not forward along request headers #76931
Replies: 1 comment
-
Following up here with my work around. Customize the loader used by export default function myImageLoader({
src,
width,
quality,
}: ImageLoaderProps) {
if (src.startsWith("https://private-media.example.com")) {
return `/api/image?url=${src}&w=${width}`;
}
// Use Next.js default loader for local images.
return `${src}?w=${width}&q=${quality || 75}`;
} Set up an My app/image route verifies user is logged in and then does the following to request the image from my private media server. const response = await fetch(url, {
headers: req.headers,
}); Be sure to set cache headers! return new NextResponse(new Uint8Array(imageBuffer), {
status: 200,
headers: {
"Cache-Control": "public, max-age=31536000, immutable",
"Content-Type": "image/png",
},
}); With these in place, I can then use |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
No response
Background
The fetch done here does not pass the headers it received. This breaks requests that require authentication.
next.js/packages/next/src/server/image-optimizer.ts
Lines 588 to 591 in f33a4b3
Proposal
Allow a next.config.js setting to enable forwarding request headers (in my case cookies).
Beta Was this translation helpful? Give feedback.
All reactions