emptygif
Language: English

All languages and frameworks

Oak TypeScript

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

Oak TypeScript

File
server.ts
Run
deno run --allow-net server.ts
import { Application, Router } from 'jsr:@oak/oak';
import { decodeBase64 } from 'jsr:@std/encoding/base64';

const GIF = decodeBase64('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==');

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

const app = new Application();
app.use(router.routes());
await app.listen({ port: 8080 });

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Oak

More in TypeScript