emptygif
Lingua: Italiano

Tutti i linguaggi e framework

srvx (universal fetch server) TypeScript

Uno snippet TypeScript per srvx (universal fetch server) che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

srvx (universal fetch server) TypeScript

Installa
npm i srvx
File
server.ts
Esegui
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',
      },
    });
  },
});

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

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

Sito ufficiale: srvx (universal fetch server)

Altro in TypeScript