emptygif
Language: English

All languages and frameworks

Google Cloud Run functions (Node.js) JavaScript

A JavaScript snippet for Google Cloud Run functions (Node.js) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Google Cloud Run functions (Node.js) JavaScript

Install
npm i @google-cloud/functions-framework
File
index.mjs
Run
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);
});

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Google Cloud Run functions (Node.js)

More in JavaScript