Cloudflare Pages Functions TypeScript
/pixel.gif へのリクエストに空の GIF を返す、Cloudflare Pages Functions 用の TypeScript スニペット。GIF は起動時に一度だけデコードします。
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' },
});
このスニペットは実行し、返されたバイト列を照合しました。
確認
curl -sI http://localhost:8080/pixel.gif
公式サイト: Cloudflare Pages Functions