emptygif
Dil: Türkçe

Tüm diller ve framework'ler

Netlify Functions TypeScript

Netlify Functions için, /pixel.gif isteklerine başlangıçta bir kez çözülen boş GIF ile yanıt veren bir TypeScript örneği.

Netlify Functions TypeScript

Kurulum
npm i -D @netlify/functions
Dosya
pixel.mts
Çalıştır
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' };

Bu örneği çalıştırıp döndürdüğü baytları karşılaştırdık.

Kontrol et

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

Resmî site: Netlify Functions

TypeScript için daha fazlası