emptygif
Idioma: Español

Todos los lenguajes y frameworks

Qwik City TypeScript

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

Qwik City TypeScript

Instalar
npm create qwik@latest
Archivo
index.ts
Ejecutar
npm run dev
// src/routes/pixel.gif/index.ts - an endpoint: no default export, just onGet
import type { RequestHandler } from '@builder.io/qwik-city';

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

export const onGet: RequestHandler = ({ send }) => {
  send(
    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: Qwik City

Más en TypeScript