emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Netlify Functions TypeScript

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

Netlify Functions TypeScript

Instal
npm i -D @netlify/functions
File
pixel.mts
Jalankan
netlify dev
// netlify/functions/pixel.mts
import type { Config } from '@netlify/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 Functions

Lainnya dalam TypeScript