emptygif
Language: English

All languages and frameworks

Azure Functions (Node.js v4 model) JavaScript

A JavaScript snippet for Azure Functions (Node.js v4 model) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Azure Functions (Node.js v4 model) JavaScript

Install
npm i @azure/functions
File
pixel.js
Run
func start
// src/functions/pixel.js
import { app } from '@azure/functions';

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

app.http('pixel', {
  methods: ['GET'],
  authLevel: 'anonymous',
  // Routes have no leading slash and sit under the "api" prefix unless
  // extensions.http.routePrefix is set to "" in host.json.
  route: '/pixel.gif'.slice(1),
  handler: async () => ({
    body: GIF,
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  }),
});

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Azure Functions (Node.js v4 model)

More in JavaScript