emptygif
Lingua: Italiano

Tutti i linguaggi e framework

React Router (framework mode, ex-Remix) TypeScript

Uno snippet TypeScript per React Router (framework mode, ex-Remix) che risponde alle richieste a /pixel.gif con la GIF vuota, decodificata una sola volta all'avvio.

React Router (framework mode, ex-Remix) TypeScript

Installa
npx create-react-router@latest
File
pixel.ts
Esegui
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',
    },
  });
}

Abbiamo eseguito questo snippet e confrontato i byte che ha restituito.

Verifica

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

Sito ufficiale: React Router (framework mode, ex-Remix)

Altro in TypeScript