emptygif
Idioma: Português

Todas as linguagens e frameworks

Netlify Edge Functions TypeScript

Um snippet em TypeScript para Netlify Edge Functions que responde às requisições para /pixel.gif com o GIF vazio, decodificado uma única vez na inicialização.

Netlify Edge Functions TypeScript

Arquivo
pixel.ts
Executar
netlify dev
// netlify/edge-functions/pixel.ts  (runs on Deno at the edge)
import type { Config } from '@netlify/edge-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' };

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

Site oficial: Netlify Edge Functions

Mais em TypeScript