emptygif
Idioma: Español

Todos los lenguajes y frameworks

Fastify JavaScript

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

Fastify JavaScript

Instalar
npm i fastify
Archivo
server.mjs
Ejecutar
node server.mjs
import Fastify from 'fastify';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

const app = Fastify();

app.get('/pixel.gif', (request, reply) => {
  reply
    .type('image/gif')
    .header('Cache-Control', 'no-store')
    .send(GIF);
});

await app.listen({ port: 8080, host: '0.0.0.0' });

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: Fastify

Más en JavaScript