emptygif
Langue: Français

Tous les langages et frameworks

TanStack Start TypeScript

Un extrait TypeScript pour TanStack Start qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

TanStack Start TypeScript

Installer
npm create @tanstack/start@latest
Fichier
pixel.ts
Lancer
npm run dev
// src/routes/pixel[.]gif.ts  (a literal dot in a file route name is escaped as [.])
import { createFileRoute } from '@tanstack/react-router';

const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export const Route = createFileRoute('/pixel.gif')({
  server: {
    handlers: {
      GET: () =>
        new Response(GIF, {
          headers: {
            'Content-Type': 'image/gif',
            'Content-Length': String(GIF.length),
            'Cache-Control': 'no-store',
          },
        }),
    },
  },
});

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: TanStack Start

Autres extraits en TypeScript