emptygif
Language: English

All languages and frameworks

Bun.serve TypeScript

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

Bun.serve TypeScript

File
server.ts
Run
bun server.ts
const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

Bun.serve({
  port: 8080,
  routes: {
    // A static Response is built once and served for every request.
    '/pixel.gif': 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: Bun.serve

More in TypeScript