emptygif
Language: English

All languages and frameworks

Koa JavaScript

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

Koa JavaScript

Install
npm i koa @koa/router
File
server.mjs
Run
node server.mjs
import Koa from 'koa';
import Router from '@koa/router';

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

const app = new Koa();
const router = new Router();

router.get('/pixel.gif', (ctx) => {
  ctx.type = 'image/gif';
  ctx.set('Cache-Control', 'no-store');
  ctx.body = GIF;
});

app.use(router.routes()).listen(8080);

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Koa

More in JavaScript