emptygif
Idioma: Português

Todas as linguagens e frameworks

Qwik City TypeScript

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

Qwik City TypeScript

Instalar
npm create qwik@latest
Arquivo
index.ts
Executar
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',
      },
    }),
  );
};

Executamos este snippet e comparamos os bytes que ele retornou.

Verificar

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

Site oficial: Qwik City

Mais em TypeScript