Skip to content

Commit 30c20aa

Browse files
committed
fixup! 404 -> 400
1 parent 252a2a9 commit 30c20aa

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

examples/playground14/e2e/cloudflare.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ test.describe("playground/cloudflare", () => {
2727

2828
test("404 when fetching an image disallowed by remotePatterns", async ({ page }) => {
2929
const res = await page.request.get("/_next/image?url=https://avatars.githubusercontent.com/u/248817");
30-
expect(res.status()).toBe(404);
30+
expect(res.status()).toBe(400);
3131
});
3232
});

packages/cloudflare/src/cli/templates/images.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type RemotePattern = {
1616
export function fetchImage(fetcher: Fetcher | undefined, imageUrl: string) {
1717
// https://github.com/vercel/next.js/blob/d76f0b1/packages/next/src/server/image-optimizer.ts#L208
1818
if (!imageUrl || imageUrl.length > 3072 || imageUrl.startsWith("//")) {
19-
return new Response("Not Found", { status: 404 });
19+
return new Response("Unsupported image config", { status: 400 });
2020
}
2121

2222
// Local
@@ -26,10 +26,10 @@ export function fetchImage(fetcher: Fetcher | undefined, imageUrl: string) {
2626
const url = new URL(imageUrl, "http://n");
2727
pathname = decodeURIComponent(url.pathname);
2828
} catch {
29-
return new Response("Not Found", { status: 404 });
29+
return new Response("Unsupported image config", { status: 400 });
3030
}
3131
if (/\/_next\/image($|\/)/.test(pathname)) {
32-
return new Response("Not Found", { status: 404 });
32+
return new Response("Unsupported image config", { status: 400 });
3333
}
3434

3535
return fetcher?.fetch(`http://assets.local${imageUrl}`);
@@ -40,15 +40,15 @@ export function fetchImage(fetcher: Fetcher | undefined, imageUrl: string) {
4040
try {
4141
url = new URL(imageUrl);
4242
} catch {
43-
return new Response("Not Found", { status: 404 });
43+
return new Response("Unsupported image config", { status: 400 });
4444
}
4545

4646
if (url.protocol !== "http:" && url.protocol !== "https:") {
47-
return new Response("Not Found", { status: 404 });
47+
return new Response("Unsupported image config", { status: 400 });
4848
}
4949

5050
if (!__IMAGES_REMOTE_PATTERNS__.some((p: RemotePattern) => matchRemotePattern(p, url))) {
51-
return new Response("Not Found", { status: 404 });
51+
return new Response("Unsupported image config", { status: 400 });
5252
}
5353

5454
return fetch(imageUrl, { cf: { cacheEverything: true } });

0 commit comments

Comments
 (0)