emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

React Router (framework mode, ex-Remix) TypeScript

Snippet TypeScript untuk React Router (framework mode, ex-Remix) yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

React Router (framework mode, ex-Remix) TypeScript

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

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: React Router (framework mode, ex-Remix)

Lainnya dalam TypeScript