emptygif
Idioma: Español

Todos los lenguajes y frameworks

Astro TypeScript

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

Astro TypeScript

Instalar
npm create astro@latest
Archivo
pixel.ts
Ejecutar
npm run dev
// src/pages/pixel.gif.ts  (on-demand rendering needs a server adapter in production)
import type { APIRoute } from 'astro';

export const prerender = false;

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

export const GET: APIRoute = () =>
  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: Astro

Más en TypeScript