emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Hono on Bun TypeScript

Snippet TypeScript untuk Hono on Bun yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Hono on Bun TypeScript

Instal
bun add hono
File
server.ts
Jalankan
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 };

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Hono on Bun

Lainnya dalam TypeScript