Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ test("kv_namspaces support", async () => {
expect(response).toBe("KV binding works");
});

test("images support", async () => {
const response = await getTextResponse("/images");
expect(response).toBe("Images binding works");
});

test("unsafe_hello_world support", async () => {
const response = await getTextResponse("/hello-world");
expect(response).toBe("Hello World binding works");
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import image from "./image.png?inline";

export default {
async fetch(request, env) {
const url = new URL(request.url);
Expand All @@ -18,6 +20,25 @@ export default {
status: 200,
});
}
case "/images": {
const request = await fetch(image);

if (!request.body) {
return new Response("Failed to fetch image", { status: 500 });
}

const info = await env.IMAGES.info(request.body);

if (info.format !== "image/png") {
return new Response("Images binding returns an incorrect format", {
status: 500,
});
}

return new Response("Images binding works", {
status: 200,
});
}
case "/ae": {
await env.WAE.writeDataPoint({ doubles: [2, 3] });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare namespace Cloudflare {
interface Env {
KV: KVNamespace;
HELLO_WORLD: HelloWorldBinding;
IMAGES: ImagesBinding;
WAE: AnalyticsEngineDataset;
RATE_LIMITER: RateLimit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"id": "test-kv-id",
},
],
"images": {
"binding": "IMAGES",
},
"unsafe_hello_world": [
{
"binding": "HELLO_WORLD",
Expand Down
Loading