emptygif
Sprache: Deutsch

Alle Sprachen und Frameworks

Netlify Functions TypeScript

Ein TypeScript-Snippet für Netlify Functions, das Anfragen an /pixel.gif mit dem leeren GIF beantwortet, das einmal beim Start dekodiert wird.

Netlify Functions TypeScript

Installieren
npm i -D @netlify/functions
Datei
pixel.mts
Ausführen
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' };

Wir haben dieses Snippet ausgeführt und die zurückgegebenen Bytes verglichen.

Prüfen

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

Offizielle Website: Netlify Functions

Mehr in TypeScript