emptygif
Wika: Filipino

Lahat ng language at framework

Google Cloud Run functions (Node.js) JavaScript

Isang JavaScript snippet para sa Google Cloud Run functions (Node.js) na sumasagot sa mga request sa /pixel.gif gamit ang empty GIF, na isang beses lang dine-decode sa startup.

Google Cloud Run functions (Node.js) JavaScript

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

Pinatakbo namin ang snippet na ito at ikinumpara ang mga byte na ibinalik nito.

Suriin

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

Opisyal na site: Google Cloud Run functions (Node.js)

Iba pa sa JavaScript