emptygif
Idioma: Español

Todos los lenguajes y frameworks

Netlify Functions TypeScript

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

Netlify Functions TypeScript

Instalar
npm i -D @netlify/functions
Archivo
pixel.mts
Ejecutar
netlify dev
// netlify/functions/pixel.mts
import type { Config } from '@netlify/functions';

const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export default () =>
  new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  });

export const config: Config = { path: '/pixel.gif' };

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Netlify Functions

Más en TypeScript