emptygif
Langue: Français

Tous les langages et frameworks

Google Cloud Run functions (Node.js) JavaScript

Un extrait JavaScript pour Google Cloud Run functions (Node.js) qui répond aux requêtes sur /pixel.gif avec le GIF vide, décodé une seule fois au démarrage.

Google Cloud Run functions (Node.js) JavaScript

Installer
npm i @google-cloud/functions-framework
Fichier
index.mjs
Lancer
npx functions-framework --target=pixel --port=8080
import * as functions from '@google-cloud/functions-framework';

const GIF = Buffer.from('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==', 'base64');

functions.http('pixel', (req, res) => {
  if (req.path !== '/pixel.gif') {
    res.sendStatus(404);
    return;
  }
  res.set('Cache-Control', 'no-store').type('gif').send(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: Google Cloud Run functions (Node.js)

Autres extraits en JavaScript