emptygif
Harshe: Hausa

Duk harsuna da frameworks

Netlify Functions TypeScript

Snippet na TypeScript don Netlify Functions da ke amsa requests zuwa /pixel.gif da empty GIF, wanda ake decoding ɗinsa sau ɗaya lokacin farawa.

Netlify Functions TypeScript

Girkawa
npm i -D @netlify/functions
Fayil
pixel.mts
Gudanar
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' };

Mun gudanar da wannan snippet kuma mun kwatanta bytes ɗin da ya mayar.

Duba shi

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

Shafin hukuma: Netlify Functions

Ƙari a TypeScript