emptygif
Language: English

All languages and frameworks

Hono on Bun TypeScript

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

Hono on Bun TypeScript

Install
bun add hono
File
server.ts
Run
bun server.ts
import { Hono } from 'hono';

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',
  }),
);

// Bun serves the default export: { fetch, port }.
export default { port: 8080, fetch: app.fetch };

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Hono on Bun

More in TypeScript