emptygif
Language: English

All languages and frameworks

Deno.serve TypeScript

A TypeScript snippet for Deno.serve that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Deno.serve TypeScript

File
server.ts
Run
deno run --allow-net server.ts
import { decodeBase64 } from 'jsr:@std/encoding/base64';

const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

Deno.serve({ port: 8080 }, (req) => {
  if (new URL(req.url).pathname !== '/pixel.gif') {
    return new Response('Not Found', { status: 404 });
  }
  return new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', '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: Deno.serve

More in TypeScript