emptygif
言語: 日本語

すべての言語・フレームワーク

RedwoodSDK TypeScript

/pixel.gif へのリクエストに空の GIF を返す、RedwoodSDK 用の TypeScript スニペット。GIF は起動時に一度だけデコードします。

RedwoodSDK TypeScript

インストール
npx create-rwsdk my-app
ファイル
worker.tsx
実行
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)]),
]);

このスニペットは実行し、返されたバイト列を照合しました。

確認

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

公式サイト: RedwoodSDK

TypeScript の他の例