emptygif
Idioma: Español

Todos los lenguajes y frameworks

React Router (framework mode, ex-Remix) TypeScript

Un fragmento en TypeScript para React Router (framework mode, ex-Remix) que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

React Router (framework mode, ex-Remix) TypeScript

Instalar
npx create-react-router@latest
Archivo
pixel.ts
Ejecutar
npm run dev
// app/routes.ts:  route('/pixel.gif', 'routes/pixel.ts')
// app/routes/pixel.ts - a resource route: a loader and no default export.
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function loader() {
  return new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  });
}

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: React Router (framework mode, ex-Remix)

Más en TypeScript