emptygif
言語: 日本語

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

Qwik City TypeScript

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

Qwik City TypeScript

インストール
npm create qwik@latest
ファイル
index.ts
実行
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',
      },
    }),
  );
};

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

確認

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

公式サイト: Qwik City

TypeScript の他の例