emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Cloudflare Pages Functions TypeScript

Snippet TypeScript untuk Cloudflare Pages Functions yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Cloudflare Pages Functions TypeScript

File
pixel.ts
Jalankan
npx wrangler pages dev public
// functions/pixel.gif.ts  (the file path is the route)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export const onRequestGet: PagesFunction = () =>
  new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  });

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

curl -sI http://localhost:8080/pixel.gif

Situs resmi: Cloudflare Pages Functions

Lainnya dalam TypeScript