emptygif
Idioma: Português

Todas as linguagens e frameworks

SvelteKit TypeScript

Um snippet em TypeScript para SvelteKit que responde às requisições para /pixel.gif com o GIF vazio, decodificado uma única vez na inicialização.

SvelteKit TypeScript

Instalar
npx sv create
Arquivo
+server.ts
Executar
npm run dev
// src/routes/pixel.gif/+server.ts
import type { RequestHandler } from './$types';

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

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

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

Site oficial: SvelteKit

Mais em TypeScript