emptygif
Idioma: Español

Todos los lenguajes y frameworks

srvx (universal fetch server) TypeScript

Un fragmento en TypeScript para srvx (universal fetch server) que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

srvx (universal fetch server) TypeScript

Instalar
npm i srvx
Archivo
server.ts
Ejecutar
npx srvx server.ts
import { serve } from 'srvx';

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

// The same code runs on Node.js, Deno and Bun.
serve({
  port: 8080,
  fetch(request) {
    if (new URL(request.url).pathname !== '/pixel.gif') {
      return new Response('Not Found', { status: 404 });
    }
    return new Response(GIF, {
      headers: {
        'Content-Type': 'image/gif',
        'Content-Length': String(GIF.length),
        'Cache-Control': 'no-store',
      },
    });
  },
});

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: srvx (universal fetch server)

Más en TypeScript