emptygif
Idioma: Español

Todos los lenguajes y frameworks

Cloudflare Pages Functions TypeScript

Un fragmento en TypeScript para Cloudflare Pages Functions que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Cloudflare Pages Functions TypeScript

Archivo
pixel.ts
Ejecutar
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' },
  });

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Cloudflare Pages Functions

Más en TypeScript