emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Hono on Bun TypeScript

Ein TypeScript-Snippet für Hono on Bun, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Hono on Bun TypeScript

Installieren
bun add hono
Datei
server.ts
Ausführen
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 };

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Hono on Bun

Mehr in TypeScript