emptygif
言語: 日本語

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

Vercel Functions TypeScript

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

Vercel Functions TypeScript

ファイル
pixel.ts
実行
vercel dev
// api/pixel.ts - served at /api/pixel; map /pixel.gif to it in vercel.json:
//   { "rewrites": [{ "source": "/pixel.gif", "destination": "/api/pixel" }] }
// (In a Next.js project use an App Router route handler instead.)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function GET() {
  return new Response(GIF, {
    headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
  });
}

このスニペットはコンパイルまたは型チェックしました。

確認

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

公式サイト: Vercel Functions

TypeScript の他の例