emptygif
Wika: Filipino

Lahat ng language at framework

React Router (framework mode, ex-Remix) TypeScript

Isang TypeScript snippet para sa React Router (framework mode, ex-Remix) na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

React Router (framework mode, ex-Remix) TypeScript

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

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: React Router (framework mode, ex-Remix)

Iba pa sa TypeScript