emptygif
Language: English

All languages and frameworks

hapi JavaScript

A JavaScript snippet for hapi that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

hapi JavaScript

Install
npm i @hapi/hapi
File
server.mjs
Run
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();

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: hapi

More in JavaScript