emptygif
Idioma: Español

Todos los lenguajes y frameworks

RedwoodSDK TypeScript

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

RedwoodSDK TypeScript

Instalar
npx create-rwsdk my-app
Archivo
worker.tsx
Ejecutar
npm run dev
// src/worker.tsx - a route before render() answers with its own Response
import { render, route } from 'rwsdk/router';
import { defineApp } from 'rwsdk/worker';

import { Document } from '@/app/document';
import { Home } from '@/app/pages/home';

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

export default defineApp([
  route('/pixel.gif', () =>
    new Response(GIF, {
      headers: {
        'Content-Type': 'image/gif',
        'Content-Length': String(GIF.length),
        'Cache-Control': 'no-store',
      },
    }),
  ),
  render(Document, [route('/', Home)]),
]);

Ejecutamos este fragmento y comparamos los bytes que devolvió.

Comprobar

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

Sitio oficial: RedwoodSDK

Más en TypeScript