emptygif
Language: English

All languages and frameworks

Hono TypeScript

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

Hono TypeScript

Install
npm i hono @hono/node-server
File
server.ts
Run
node server.ts
import { Hono } from 'hono';
import { serve } from '@hono/node-server';

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

const app = new Hono();

app.get('/pixel.gif', (c) =>
  c.body(GIF, 200, {
    'Content-Type': 'image/gif',
    'Cache-Control': 'no-store',
  }),
);

// On Bun, Deno or Cloudflare Workers use `export default app` instead.
serve({ fetch: app.fetch, port: 8080 });

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Hono

More in TypeScript