emptygif
Langue: Français

Tous les langages et frameworks

Netlify Functions TypeScript

Un extrait TypeScript pour Netlify Functions qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Netlify Functions TypeScript

Installer
npm i -D @netlify/functions
Fichier
pixel.mts
Lancer
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' };

Nous avons exécuté cet extrait et comparé les octets qu’il a renvoyés.

Vérifier

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

Site officiel: Netlify Functions

Autres extraits en TypeScript