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
// 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