emptygif
Idioma: Español

Todos los lenguajes y frameworks

Encore.ts TypeScript

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

Encore.ts TypeScript

Instalar
encore app create --example=ts/hello-world
Archivo
pixel.ts
Ejecutar
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);
  },
);

Revisado según la documentación actual del framework.

Comprobar

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

Sitio oficial: Encore.ts

Más en TypeScript