emptygif
Idioma: Español

Todos los lenguajes y frameworks

Vercel Functions TypeScript

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

Vercel Functions TypeScript

Archivo
pixel.ts
Ejecutar
vercel dev
// api/pixel.ts - served at /api/pixel; map /pixel.gif to it in vercel.json:
//   { "rewrites": [{ "source": "/pixel.gif", "destination": "/api/pixel" }] }
// (In a Next.js project use an App Router route handler instead.)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function GET() {
  return new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  });
}

Compilamos este fragmento o comprobamos sus tipos.

Comprobar

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

Sitio oficial: Vercel Functions

Más en TypeScript