emptygif
Idioma: Español

Todos los lenguajes y frameworks

hapi JavaScript

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

hapi JavaScript

Instalar
npm i @hapi/hapi
Archivo
server.mjs
Ejecutar
node server.mjs
import Hapi from '@hapi/hapi';

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

const server = Hapi.server({ port: 8080 });

server.route({
  method: 'GET',
  path: '/pixel.gif',
  handler: (request, h) =>
    h.response(GIF).type('image/gif').header('Cache-Control', 'no-store'),
});

await server.start();

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: hapi

Más en JavaScript