emptygif
語言: 繁體中文

所有語言和框架

Google Cloud Run functions (Node.js) JavaScript

適用於 Google Cloud Run functions (Node.js) 的 JavaScript 程式碼片段,以空 GIF 回應對 /pixel.gif 的請求,GIF 在啟動時只解碼一次。

Google Cloud Run functions (Node.js) JavaScript

安裝
npm i @google-cloud/functions-framework
檔案
index.mjs
執行
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);
});

我們執行了這段程式碼,並比對了它回傳的位元組。

驗證

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

官方網站: Google Cloud Run functions (Node.js)

更多 JavaScript 範例