emptygif
Bahasa: Bahasa Indonesia

Semua bahasa dan framework

Google Cloud Run functions (Node.js) JavaScript

Snippet JavaScript untuk Google Cloud Run functions (Node.js) yang menjawab request ke /pixel.gif dengan empty GIF, yang di-decode sekali saat startup.

Google Cloud Run functions (Node.js) JavaScript

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

Kami telah menjalankan snippet ini dan membandingkan byte yang dikembalikannya.

Periksa

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

Situs resmi: Google Cloud Run functions (Node.js)

Lainnya dalam JavaScript