emptygif
Langue: Français

Tous les langages et frameworks

Hono on Bun TypeScript

Un extrait TypeScript pour Hono on Bun qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Hono on Bun TypeScript

Installer
bun add hono
Fichier
server.ts
Lancer
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 };

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: Hono on Bun

Autres extraits en TypeScript