emptygif
Language: English

All languages and frameworks

Firebase Cloud Functions + Hosting JavaScript

A JavaScript snippet for Firebase Cloud Functions + Hosting that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Firebase Cloud Functions + Hosting JavaScript

Install
npm i firebase-functions firebase-admin
File
index.js
Run
firebase emulators:start
// functions/index.js - and in firebase.json:
//   "hosting": { "rewrites": [{ "source": "/pixel.gif", "function": { "functionId": "pixel" } }] }
import { onRequest } from 'firebase-functions/https';

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

export const pixel = onRequest((req, res) => {
  res.set('Cache-Control', 'no-store').type('gif').send(GIF);
});

We compiled or type-checked this snippet.

Check it

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

Official site: Firebase Cloud Functions + Hosting

More in JavaScript