emptygif
Idioma: Español

Todos los lenguajes y frameworks

SvelteKit TypeScript

Un fragmento en TypeScript para SvelteKit que responde a las peticiones a /pixel.gif con el GIF vacío, decodificado una sola vez al arrancar.

SvelteKit TypeScript

Instalar
npx sv create
Archivo
+server.ts
Ejecutar
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',
    },
  });

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: SvelteKit

Más en TypeScript