emptygif
Language: English

All languages and frameworks

srvx (universal fetch server) TypeScript

A TypeScript snippet for srvx (universal fetch server) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

srvx (universal fetch server) TypeScript

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

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: srvx (universal fetch server)

More in TypeScript