emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Netlify Edge Functions TypeScript

Snippet TypeScript untuk Netlify Edge Functions yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Netlify Edge Functions TypeScript

File
pixel.ts
Jalankan
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' };

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Netlify Edge Functions

Lainnya dalam TypeScript