Skip to content

Commit 35db67f

Browse files
committed
fix(judge-lab): tolerate missing image bindings
1 parent d1afa9b commit 35db67f

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

judge-lab/tests/rendered-html.test.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ test("health endpoint reports engine and build provenance", async () => {
6262
assert.deepEqual(payload.evidenceModes, ["live", "precomputed"]);
6363
});
6464

65+
test("image optimization endpoint does not crash without local worker bindings", async () => {
66+
const worker = await createWorker();
67+
const response = await worker.fetch(
68+
new Request("http://localhost/_vinext/image?url=%2Flogo.png&w=128&q=75"),
69+
{},
70+
context,
71+
);
72+
73+
assert.notEqual(response.status, 500);
74+
});
75+
6576
test("live endpoint finds the curated anonymous admin route", async () => {
6677
const worker = await createWorker();
6778
const response = await worker.fetch(

judge-lab/worker/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "vinext/server/image-optimization";
99

1010
interface Env {
11-
ASSETS: Fetcher;
11+
ASSETS?: Fetcher;
1212
DB: D1Database;
13-
IMAGES: {
13+
IMAGES?: {
1414
input(stream: ReadableStream): {
1515
transform(options: Record<string, unknown>): {
1616
output(options: { format: string; quality: number }): Promise<{ response(): Response }>;
@@ -39,8 +39,19 @@ const worker = {
3939
return handleImageOptimization(
4040
request,
4141
{
42-
fetchAsset: (path) => env.ASSETS.fetch(new Request(new URL(path, request.url))),
42+
fetchAsset: (path) => {
43+
if (!env.ASSETS) {
44+
return Promise.resolve(new Response("Not found", { status: 404 }));
45+
}
46+
return env.ASSETS.fetch(new Request(new URL(path, request.url)));
47+
},
4348
transformImage: async (body, { width, format, quality }) => {
49+
if (!env.IMAGES) {
50+
return new Response(body, {
51+
headers: { "content-type": `image/${format}` },
52+
status: 200,
53+
});
54+
}
4455
const result = await env.IMAGES.input(body)
4556
.transform(width > 0 ? { width } : {})
4657
.output({ format, quality });

0 commit comments

Comments
 (0)