emptygif
Idioma: Español

Todos los lenguajes y frameworks

Hono TypeScript

Un fragmento en TypeScript para Hono que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

Hono TypeScript

Instalar
npm i hono @hono/node-server
Archivo
server.ts
Ejecutar
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 });

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Hono

Más en TypeScript