emptygif
言語: 日本語

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

Netlify Edge Functions TypeScript

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

Netlify Edge Functions TypeScript

ファイル
pixel.ts
実行
netlify dev
// netlify/edge-functions/pixel.ts  (runs on Deno at the edge)
import type { Config } from '@netlify/edge-functions';

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

export default () =>
  new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  });

export const config: Config = { path: '/pixel.gif' };

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

確認

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

公式サイト: Netlify Edge Functions

TypeScript の他の例