emptygif
Language: English

All languages and frameworks

Encore.ts TypeScript

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

Encore.ts TypeScript

Install
encore app create --example=ts/hello-world
File
pixel.ts
Run
encore run
// pixel/pixel.ts  (inside a service directory with an encore.service.ts)
import { api } from 'encore.dev/api';

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

// A raw endpoint gets Node's req/res, so the bytes are written untouched.
export const pixel = api.raw(
  { expose: true, method: 'GET', path: '/pixel.gif' },
  async (req, resp) => {
    resp.writeHead(200, {
      'Content-Type': 'image/gif',
      'Content-Length': GIF.length,
      'Cache-Control': 'no-store',
    });
    resp.end(GIF);
  },
);

Checked against the framework's current documentation.

Check it

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

Official site: Encore.ts

More in TypeScript